C Sharp – die besten Beiträge

Unity: Wieso läuft die Registrierung schief?

Hallo,

ich bin gerade dabei, ein Unity-Spiel zu programmieren. In dem Spiel soll man sich registrieren können, dabei benutze ich PlayFab. Bei dem Test der Registrierung läuft etwas schief und ich weiß einfach nicht wieso. Vielleicht könnt ihr mir weiterhelfen?

Danke für jede Antwort.

Unity:

Das Spiel:

Das Skript:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab.ClientModels;
using PlayFab;
using System;
using UnityEditor.PackageManager.Requests;
using UnityEngine.UI;
using TMPro;
using PlayFab.PfEditor;

public class PlayFabLoginScript : MonoBehaviour
{
  public TextMeshProUGUI regPassword, regUsername, regEmail;
  public GameObject regPanel;

  // Start is called before the first frame update
  void Start()
  {
    var request = new LoginWithCustomIDRequest { CustomId = "GettingStardedGuide", CreateAccount = true };
    PlayFabClientAPI.LoginWithCustomID(request, OnLoginSucces, OnLoginFailure);
  }

  private void OnLoginFailure(PlayFabError obj)
  {
    Debug.Log("Es ist etwas schief gelaufen");
  }

  private void OnLoginSucces(LoginResult obj)
  {
    Debug.Log("API Call hat funktioniert");
  }

  public void Register()
  {
    var request = new RegisterPlayFabUserRequest();
    request.TitleId = PlayFabSettings.TitleId;
    request.Email = regEmail.text;
    request.Username = regUsername.text;
    request.Password = regPassword.text;
    PlayFabClientAPI.RegisterPlayFabUser(request, OnRegisterResult, OnPlayFabError);
  }

  private void OnPlayFabError(PlayFabError obj)
  {
    print("Error:" + obj.Error);
  }

  private void OnRegisterResult(RegisterPlayFabUserResult obj)
  {
    print("Registrierung hat funktioniert");
    regPanel.SetActive(false);
  }
Bild zum Beitrag
C Sharp, Code, Programmiersprache, Spieleentwicklung, Visual Studio, 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