Monday, December 23, 2024
HomeGame Developmentunity - Injury not utilized to the participant

unity – Injury not utilized to the participant


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

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

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

    void OnCollisionEnter(Collision different)
    {
        print("collision set off works");
        if(different.rework.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;

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

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

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

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments