sorry i don’t know to understand you the quastion
I use this script to shoot and i want to shoot through some object help
function Shoot(){
if (shotSound) audio.PlayOneShot(shotSound); // play the shot sound
var hit: RaycastHit;
var DirectionRay = SprayDirection();
CanFire = false;
Ammo -=1;
Debug.DrawRay(transform.position, DirectionRay * Range, Color.blue);
if(Physics.Raycast(transform.position, DirectionRay, hit, Range)){
// prepare rotation to instantiate blood or sparks
var rot = Quaternion.FromToRotation(Vector3.up, hit.normal);
if (hit.transform.tag == "Enemy"){ // if enemy hit...
if (bloodPrefab) Instantiate(bloodPrefab, hit.point, rot); // make it bleed...
CrossHair.renderer.material.SetColor ("_Color", Color.red);
hit.transform.SendMessage("ApplyDamage", 10, SendMessageOptions.DontRequireReceiver); // and consume its health
}
if (hit.transform.tag == "Target"){ // if enemy hit...
if (sparksPrefab) Instantiate(sparksPrefab, hit.point, rot); // make it bleed...
CrossHair.SetActiveRecursively(false);
CrossHairHit.SetActiveRecursively(true);
hit.transform.SendMessage("ApplyDamage", 10, SendMessageOptions.DontRequireReceiver); // and consume its health
}
if (hit.transform.tag == "Wood"){// otherwise emit sparks at the hit point
if (sparksPrefab) Instantiate(sparksPrefab, hit.point, rot);
}
if (hit.transform.tag == "Iron"){ // if enemy hit...
if (ironPrefab) Instantiate(ironPrefab, hit.point, rot);
}
if (hit.transform.tag == "Glass"){ // if enemy hit...
if (glassPrefab) Instantiate(glassPrefab, hit.point, rot); // make it bleed...
hit.transform.SendMessage("ApplyDamage", 5, SendMessageOptions.DontRequireReceiver); // and consume its health
}
if (hit.transform.tag == "Terrain"){ // if enemy hit...
if (terrainPrefab) Instantiate(terrainPrefab, hit.point, rot);
}
if (hit.transform.tag == "Water"){ // if enemy hit...
if (waterPrefab) Instantiate(waterPrefab, hit.point, rot);
}
}
yield WaitForSeconds(FireRate);
CanFire = true;
}
If you want to shoot through some of the gameobjects, look at raycast mask.
– Chronos-LYou can use a mask in the raycast to selectively ignore one or few layers, if a gameobject/collider belongs to this layer, it will not interact/interfere with the raycast (so you sort of shoot through the gameobject). http://answers.unity3d.com/questions/8715/how-do-i-use-layermasks.html
– Chronos-L@alucardj, your comment disappear from here but I can see it in my mail inbox. That's a interesting competition, I supposed that there is no limit to what sort of tool I can use in the competition? I will keep an eye on the website and I might participate the next competition.
– Chronos-LThanks! :)
– Fr0stbite