Home Game Development unity – Damage not utilized to the participant

unity – Damage not utilized to the participant

0
unity – Damage not utilized to the participant

[ad_1]

I created a turret firing missile to participant however for some cause the injury isn’t utilized to the participant, and the missile isn’t firing appropriately: collision isn’t triggered. Here’s my code. I can’t perceive what might presumably be the rationale.

public class DamageParticipant : MonoBehaviour
{
    
    public GameObject participant;
    personal PlayerHealth _playerHealth;

    void Start()
    {
        if (participant != null)
        {
            _playerHealth = participant.remodel.GetComponent<PlayerHealth>();
        }
        else
        {
            print("participant Gameobject not discovered");
        }
    }

    void OnCollisionEnter(Collision different)
    {
        print("collision set off works");
        if(different.remodel.tag == "Rocket")
        {
            _playerHealth.playerHealth = _playerHealth.playerHealth - 10;
            print(_playerHealth.playerHealth);
        }
    }
}
public GameObject rocketPrefab;
public GameObject spawnPoint;
personal bool _firing;
public float fireRate;
public bool turretActive = true;

// Update is known as as soon as per body
void Update()
{
    if (turretActive)
    {
        if (!_firing)
        {
            FireTheRocket();
            StartCoroutine(RateOfFire());
        }
    }
}

void FireTheRocket()
{
    Instantiate(rocketPrefab, spawnPoint.remodel.TransformPoint(0, 0, 0), spawnPoint.remodel.rotation);
}

IEnumerator RateOfFire()
{
    _firing = true;
    yield return new WaitForSeconds(fireRate);
    _firing = false;
}

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here