- Home /
Question by
bryan · May 10, 2012 at 01:06 AM ·
mobiletouchraycastingcasting
Ray Casting iOS
Im using the Standard Assets (Mobile) First Person Controls, so i have the two joysticks on screen. I'm trying to make a script that every time you tap on the screen it shoots a ray cast out in that direction to check the tag of the object the ray collided with. my script is not working there are no errers in unity.
(Shoot Script)
var hit : RaycastHit;
public var damage: float = 10;
function Update () { // Use Raycast to pick object that has mesh colliders attached...
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Input.GetMouseButtonDown (0))
{
if (Physics.Raycast (ray, hit, 100))
{
if(tag == "Enemy")
{
SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}
if(tag == "Trigger")
{
SendMessage("Activate", SendMessageOptions.DontRequireReceiver);
}
}
}
}
Comment