Hi I’m trying to make an rts game with special units, like heroes, and I’m making the skill sistem, and this skill throw a knife into the enemy. But when it collides it does nothing.
public class Player_Skill : MonoBehaviour {
public float QCooldown;
private float Qtimer=0;
public float speed;
public GameObject prefab;
void Start () {
prefab = Resources.Load("projectile") as GameObject;
}
// Update is called once per frame
void Update () {
QCooldown -= Time.deltaTime;
if (QCooldown <= 0 && Input.GetKeyDown("q"))
{
Plane playerPlane = new Plane(Vector3.up, transform.position);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float hitdist = 0.0f;
if (playerPlane.Raycast(ray, out hitdist))
{
Vector3 targetPoint = ray.GetPoint(hitdist);
Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);
}
GameObject projectile = Instantiate(prefab) as GameObject;
projectile.transform.position = transform.position+transform.forward *2;
Rigidbody rb = projectile.GetComponent<Rigidbody>();
rb.velocity = transform.forward * 300;
QCooldown = 10;
}
// GameObject.Destroy(prefab);
Debug.Log("cooldown"+QCooldown);
}
void OnColliderHit(Collider collision)
{
if (collision.gameObject.tag == "Minion2" || collision.gameObject.tag == "P2")
{
DestroyObject(collision.gameObject);
}
}
}