Warum kann ich den Typ "InputManager" in Unity nicht nutzen ohne Error?

Hallo an alle,

ich bin sehr neu im Bereich Spieleentwicklung mit Unity und möchte ein simples Spiel programmieren, in dem man verschiedene Räume gestalten kann. also hab ich mir ein Tutorial herausgesucht ( https://www.youtube.com/watch?v=l0emsAHIBjU&list=PLcRSafycjWFepsLiAHxxi8D_5GGvu6arf ) in dem dies erklärt wird. Bei 3:47 benutzt er den Typ "InputManager" im zweiten SerializeField.

Wenn ich jedoch das Script so kopiere wie er es im Video schreibt, zeigt mir Unity einen Fehler bei "InputManager" an. Da er im Video sagt, dass er das alte Input System nutzt hab ich dieses auch eingestellt.

Da ich nicht wirklich viel Ahnung von dem habe was er da schreibt, hab ich im Internet nach einer Lösung gesucht, doch scheinbar nutzt niemand diesen Typ. Vielen Dank im Voraus für die Antwort

P.S.: Ich habe ein Bild von Visual Studio eingefügt in dem auch der Error zu sehen ist.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class PlacementSystem : MonoBehaviour
{
    [SerializeField]
    private GameObject mouseIndicator;
    [SerializeField]
    private InputManager inputManager;


    private void Update()
    {
        Vector3 mousePosition = inputManager.GetSelectedMapPosition();
        mouseIndicator.transform.position = mousePosition;
    }
}
Bild zum Beitrag
Software, C Sharp, Code, Error, Fehlerbehebung, Programmiersprache, Spieleentwicklung, Unity 3D, Visual Studio, Fehlermeldung, input, Unity
Was ist falsch mit diesem Script (Unity, C#)?

Hallo,

ich bin im Moment dabei, mir selbst Unity bei zu bringen. Wie man sieht habe ich aber Probleme.

Was ich machen möchte ist eigentlich recht simple - Ich möchte eine Intro-Sequenz am Anfang des Spiels haben, die 3 Texte nacheinander Visible macht und dann am Ende kann man dann drücken um das Spiel zu starten, sprich den Intro Frame unsichtbar zu machen. Ich habe aber nur Probleme mit dem "wait" Befehl, da dieser hier komischerweise sehr unnötog kompliziert gemacht wurde. Anstatt eines einfachen "wait()-Befehls" oder so muss man ja irgendwas mit diesen "IEnumeratorn" machen. Ich habe mir auch schon Tutorials angeschaut, komme hier aber nicht zu irgendeinem guten Ergebnis, sobald ich die wait Funktion nutze.

Kennt sich hier vielleicht irgendjemand aus? Wäre sehr cool wenn ihr mir helft.

Nur zu Info: Ich bin kein Profi, also bitte hatet mich nicht wenn es sehr offensichtlich ist oder so.

Hier mein Script:

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;

public class Script1 : MonoBehaviour
{
  public GameObject Intro;
  public GameObject StartText;
  public GameObject Text1;
  public GameObject Text2;
  public GameObject Text3;
  public bool IsEnabled = false;
   
  // Start is called before the first frame update
  void Start()
  {
    Text1.SetActive(false);
    Text2.SetActive(false);
    Text3.SetActive(false);
    StartText.SetActive(false);
    Initialise();
  }

  IEnumerator Initialise()
  {
    Text1.SetActive(true);
    yield return new WaitForSeconds(2f);
    Text2.SetActive(true);
    yield return new WaitForSeconds(2f);
    Text3.SetActive(true);
    yield return new WaitForSeconds(2f);
    StartText.SetActive(true);
    IsEnabled = true;
  }

  // Update is called once per frame
  void Update()
  {
    if (IsEnabled == true)
    {
       
      if (Input.GetKeyDown(KeyCode.Mouse0))
      {
        Intro.SetActive(false);
        IsEnabled = false;
      }
    }
  }
}

Hier nochmal als Bild aus Visual Studio falls es jemand braucht:

Bild zum Beitrag
C Sharp, Code, Programmiersprache, Spieleentwicklung, UI, Unity 3D, Unity
Könnt ihr mir bei meinem Skript helfen?

Hallo, ich habe die letzten Stunden ein Skript programmiert, aber es funktioniert nicht. Mir wird GetComponent<ShootingAi> falsch angezeigt. Die letzten Male hat es noch funktioniert, aber jetzt nicht mehr.

Hier ist das Skript. Der Fehler ist bei // RayCast:

using System.Collections;
using System.Collections.Generic;
using System.Xml.Serialization;
using UnityEngine;
using TMPro;

public class GunSystem : MonoBehaviour
{
  // Werte
  public int damage;
  public float timeBetweenShooting;
  public float spread;
  public float range;
  public float reloadTime;
  public float timeBetweenShots;
  public int magazineSize;
  public int bulletsPerTap;
  public bool allowButtonHold;
  private int bulletsLeft;
  private int bulletsShot;

  // Bool
  bool shooting;
  bool readyToShoot;
  bool reloading;

  // Referenz
  public Camera fpsCam;
  public Transform attackpoint;
  public RaycastHit rayHit;
  public LayerMask whatIsEnemy;

  // Grafik
  public GameObject muzzleFlash;
  public GameObject bulletHoleGraphic;
  public float camShakeMagnitude;
  public float camShakeDuration;
  public TextMeshProUGUI text;

  private void Awake()
  {
    bulletsLeft = magazineSize;
    readyToShoot = true;
  }

  private void Update()
  {
    MyInput();
    text.SetText(bulletsLeft + "/" + magazineSize);
  }

  private void MyInput()
  {
    if (allowButtonHold)
    {
      shooting = Input.GetKey(KeyCode.Mouse0);
    }
    else
    {
      shooting = Input.GetKeyDown(KeyCode.Mouse0);
    }

    if (Input.GetKeyDown(KeyCode.R) && bulletsLeft < magazineSize && !reloading)
    {
      Reload();
    }

    // Shoot
    if (readyToShoot && shooting && !reloading && bulletsLeft > 0)
    {
      bulletsShot = bulletsPerTap;
      Shoot();
    }
  }

  private void Shoot()
  {
    readyToShoot = false;
    // Spread
    float x = Random.Range(-spread, spread);
    float y = Random.Range(-spread, spread);

    // Calculate Direction with Spread
    Vector3 direction = fpsCam.transform.forward + new Vector3(x, y, 0);

    // RayCast
    if (Physics.Raycast(fpsCam.transform.position, direction,  out rayHit, range, whatIsEnemy))
    {
      Debug.Log(rayHit.collider.name);

      if (rayHit.collider.CompareTag("Enemy"))
      {
        rayHit.collider.GetComponent<ShootingAi>().TakeDamage(damage);
      }
    }

    // Graphics
    Instantiate(bulletHoleGraphic, rayHit.point, Quaternion.Euler(0, 180, 0));
    Instantiate(muzzleFlash,attackpoint.position, Quaternion.identity);

    bulletsLeft--;
    bulletsShot--;

    Invoke("ResetShot", timeBetweenShooting);

    if (bulletsShot > 0 && bulletsLeft > 0)
    {
      Invoke("Shoot", timeBetweenShots);
    }
  }

  private void ResetShot()
  {
    readyToShoot = true;
  }

  private void Reload()
  {
    reloading = true;
    Invoke("ReloadFinished", reloadTime);
  }

  private void ReloadFinished()
  {
    bulletsLeft = magazineSize;
    reloading = false;
  }
}

Ich komme echt nicht mehr weiter und bräuchte etwas Hilfe.

C Sharp, Visual Studio, Unity

Meistgelesene Beiträge zum Thema C Sharp