Im creating a Tower Defence game and I can’t get the bullet to acess the script on the enemy and start taking health off.
This is the Health Script
using UnityEngine;
using System.Collections;
public class Health : MonoBehaviour
{
public float health = 100f;
void Update()
{
if (health <= 0) {
Destroy (gameObject);
}
}
}
and this is the Bullet Script
using UnityEngine;
using System.Collections;
Thank you,
Im also having an issue in which it is only shooting one bullet at each enemy, not at the intervals that I set.
using UnityEngine;
using System.Collections;
public class Tower : MonoBehaviour
{
public GameObject bulletPrefab;
public float rotationSpeed =35;
public float interval = 1;
It’s because you can’t use Invoke for methods with parameters (OnTriggerEnter has the Collision parameter). To be honest OnTriggerEnter is a method normally saved only for when objects collide with each other, and is called automatically by the physics engine in Unity. Your best bet would be to make your own method and call that one instead, which has no parameters: