- Home /
Problem with collision - Collision.other.gameObject is obsolete
Hi all! Got a problem with a script!
I got an enemie that when it's hit by either a laser or a missile from my player, it's take a certain amount of damage and it's based on the tag of the colliding object.
Before you could just use Collision.other.gameObject.tag for the other colliding object (in this case either my laser or missile) But now it's OBSOLETE!!!!!
Unity says to use Rigidbody or Collider but i dont know hell how to do that!!! Here's my code any help would be great!! How do you refer to the other colliding object???
#pragma strict
public var startingHealth : int =5;
private var enemyHealth : int;
function Start ()
{
enemyHealth = startingHealth;
}
function Update ()
{
CheckHp();
}
function Hit(damage:int)
{
enemyHealth -= damage;
Debug.Log("Taking DMG");
}
function CheckHp()
{
if(enemyHealth <= 0)
{
Destroy(gameObject);
}
}
function OnCollisionEnter(collision : Collision )
{
if(collision.other.gameObject.tag == "Plaser")
{
Debug.Log("Ouch");
Hit(2);
}
if(collision.other.gameObject.tag == "Pmissile")
{
Debug.Log("Ouch");
Hit(5);
}
}
Answer by dorpeleg · Jul 03, 2013 at 03:01 PM
It should be collision.collider.gameObject.tag.
I've just tried with the collision.collider.gameObject.tag like you said. Now i don't have the obsolete message anymore but the collision doesn't occur! I don't have the Log "Ouch" that print.
But I have a rigidbody attached to my laser and missile maybe it's that ????
Well Dorpeleg you were right!!! I'm sorry!! made a mistake by mispelling the thing!!! Everything works fine thank you!!!