Unity 3D – die besten Beiträge

Wie fixt man diesen unity Fehler?

hi; ich mache grade ein FPS Shooter game und habe das Problem das wenn ich im Skript für die Waffe den Damage auf 30 setze hat der Enemy mit einem Schuss nur noch 30hp aber dann ist er unsterblich.

Hier das gun skript

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Gun : MonoBehaviour

{

  public float damage = 10f;

  public float range = 100f;

  public float Firerate = 15f;

  public Camera fpscam;

  private float nextTimeToFire = 0f;

  // Start is called before the first frame update

  void Start()

  {

  }

  // Update is called once per frame

  void Update()

  {

    if (Input.GetMouseButton(0) && Time.time >= nextTimeToFire)

    {

      nextTimeToFire = Time.time + 1f / Firerate;

      Shoot();

    }

  }

  void Shoot()

  {

    RaycastHit hit;

    if (Physics.Raycast(fpscam.transform.position, fpscam.transform.forward, out hit, range))

    {

      Opfer opfer = hit.transform.GetComponent<Opfer>();

      if (opfer != null)

      {

        opfer.TakeDamage(damage);

      }

      Debug.Log(hit.transform.name);

    }

  }

}

und hier das Enemy Health skript

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Opfer : MonoBehaviour

{

  public float health = 100f;

  public void TakeDamage(float amount)

  {

    health = amount;

    if(health <= 0)

    {

      Destroy(gameObject);

    }

  }

}

und das Enemy skript

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.AI;

public class EnamyManager : MonoBehaviour

{

  public GameObject Player;

  public Animator enemyAnimator;

  public float damage = 30f;

  // Start is called before the first frame update

  void Start()

  {

    Player = GameObject.FindGameObjectWithTag("Player");

  }

  // Update is called once per frame

  void Update()

  {

    GetComponent<NavMeshAgent>().destination = Player.transform.position;

    if (GetComponent<NavMeshAgent>().velocity.magnitude > 1)

    {

      enemyAnimator.SetBool("isRuning", true);

    }

    else

    {

      enemyAnimator.SetBool("isRuning", false);  

    }

  }

  private void OnCollisionEnter(Collision collision)

  {

    if(collision.gameObject == Player)

    {

      Player.GetComponent<PlayerManager>().Hit(damage);

    }

  }

}

Vielen dank wenn mir jemand helfen kann

Error, Unity 3D

Meistgelesene Beiträge zum Thema Unity 3D