Hi i’m looking the best way to apply damage via raycast.
using this script, I know the tag gameobject hit, but how can I apply damage?
I have many gameobject with the same tags.
i need other script attached gameobject enemy?
SendMessage can be the solution? how to use this?
var shoot: GUITexture;
public var camera1:Camera;
var crosshairs:Texture;
function Awake(){
shoot= GameObject.Find("shoot").guiTexture;
}
function Update () {
for(var touch : Touch in Input.touches){
if(touch.phase == TouchPhase.Ended && shoot.HitTest (touch.position))){
animation.Play("shoot");
audio.Play();
ShootFunction();
}
}
function OnGUI() {
GUI.DrawTexture(new Rect(Screen.width / 2, Screen.height / 2, 50, 50), crosshairs);
}
function ShootFunction()
{
var ray : Ray = camera1.ViewportPointToRay (Vector3(0.5,0.5,0));
var hit:RaycastHit;
if (Physics.Raycast(ray, hit)){
Debug.Log("Hit " + hit.collider.tag);}
}