public var rayDirection : Ray;
static public var applyDamage : boolean = false;
public var bloodSplash : GameObject;
private var blood1;
function Update(){
var Forward = transform.TransformDirection(Vector3.up);
var rayDirection = Physics.Raycast(transform.position, Forward, 500);
Debug.DrawRay(transform.position, Forward * 1000, Color.green);
var rayHit : RaycastHit;
if(Input.GetKeyDown(KeyCode.Mouse0)){
shotFire = Instantiate(skottEld, transform.position,transform.rotation); //particles
Destroy(shotFire, 3);
ammo = ammo - 1;
if(Physics.Raycast(transform.position, transform.up ,rayHit,10)){
//var objectHit : GameObject = rayHit.Collider.gameObject;
if(rayHit.collider == "Target"){
Debug.Log("Hit");
blood1 = Instantiate(bloodSplash, rayHit.point,Quaternion.LookRotationrotation
(rayHit.normal));
Destroy(blood1, 2);
applyDMG();
}
}
The script will be attached to a gun or main camera.
I want the bloodSplash to instantiate at the target(enemy) aswell as do my applyDMG function, the applyDMG should work. The problem is the raycast, I am very new to raycasting and would really appreciate some help!
It’s all become a great mess because I have tried different ways of solving it and now I am just lost. Thanks in advance! /Fetdressing