well, I’d like to Instantiate a line from my camera and make it go through all colliders in the scene, then I apply the function SendMessage() so that I can apply a damage to it; Here’s the code:
var proiettile : GameObject;
var damange : int = 10;
var tempo_tra_colpi : float = 0.2;
function Start(){
}
function FixedUpdate () {
if (Input.GetButton("Fire1")){
if (Time.time >= tempo_tra_colpi){
Shoot();
}
}
}
function Shoot(){
var ray : Ray = camera.main.ScreenPointToRay(Vector3(Screen.width/2,Screen.height/2,0));
Debug.DrawRay(ray.origin, ray.direction*Mathf.Infinity, Color.blue);
var hit: RaycastHit;
bullet = Instantiate(proiettile, ray.origin, Quaternion.identity);
Physics.IgnoreCollision(collider, bullet.collider);
bullet.rigidbody.AddForce(ray.direction*1000, ForceMode.Force);
Destroy(bullet, 3);
if(Physics.Linecast(ray.origin, ray.origin.forward*1000, hit)){
for (var i : GameObject in hit){
i.transform.SendMessageUpwards("ApplyDamage", damange, SendMessageOptions.DontRequireReceiver);
}
}
}