- Home /
The problems of Collider ....
I built a laser tower to attack enemies.
Tower Code :
var hit : RaycastHit;
Physics.Raycast(Vector3(transform.position.x, transform.position.y + 2, transform.position.z), transform.forward, hit , attackingRange);
if (hit.collider)
{
lineRenderer.SetPosition(1,Vector3(0,0,Mathf.Sqrt(attackingRange)));
print(hit.collider.gameObject.tag);
}
I can get the hit.collider.gameObject.tag is Enemy.
Enemy Code :
function OnTriggerEnter( hit : Collider)
{
print(hit.gameObject.tag);
}
get nothing.........
why why why....??? anyone can help me??
Answer by Mike 3 · Nov 01, 2010 at 09:05 PM
Raycasts don't cause collisions if that's what you're getting at
If you need to tell the enemy code to do something, try using SendMessage instead, or possibly GetComponent and then call a function
Hi, $$anonymous$$ike. You can check my another question, I tried to use Send$$anonymous$$essage or GetComponent to solve this problem. (http://answers.unity3d.com/questions/25796/a-problem-about-broadcastmessage-and-getcomponent-please-help-me) Please help me~~~ tell me how to do ...
Dear $$anonymous$$ike, I used GetComponent, the error is "NullReferenceException: Object reference not set to an instance of an object". Then I tried Broadcast$$anonymous$$essage/Send$$anonymous$$essage, I got "Broadcast$$anonymous$$essage Energy has no receiver!"..
The problem is probably because you're doing it no matter what you hit. Try Send$$anonymous$$essage("FunctionName", Send$$anonymous$$essageOptions.DontRequireReceiver); if you don't want to check the tag before doing Send$$anonymous$$essage
Dear $$anonymous$$ike, I used Send$$anonymous$$essage("Energy", Send$$anonymous$$essageOptions.DontRequireReceiver); when enemies' HP <= 0. Then, I wrote a function Energy (){ print(energyValue); } in Vortex tower script and get nothing, I'm sure there is a vortex tower in the scene. How could I do ?
hit.gameObject.Send$$anonymous$$essage("Energy", Send$$anonymous$$essageOptions.DontRequireReceiver); is probably what you want, so it sends it to the object that is hit