- Home /
Shooting question
I can shoot a rigid-body but how can I make the object I am shooting invisible? Any suggestions or tutorials. here Is my code if someone want to try and modify it. Any thing would be useful. Thank you for all the help. (The script in in java)(sorry if the code comes out funky)
var bullet: Rigidbody;
var speed = 50;
var AMMO = 5;
var c : AudioSource;
function Update()
{
if(Input.GetButtonDown("Fire2"))
{
if(AMMO > 0)
{
animation.Play("shoot");
audio.Play();
var clonedBullet : Rigidbody = Instantiate(bullet,transform.position,transform.rotation);
clonedBullet.velocity = transform.TransformDirection(Vector3(0,0,speed));
AMMO --;
}
else{
c.audio.Play();
animation.Play("reload");
AMMO = 5;
}
}
}
Format your code by indenting it 4 space or 1 tab or by highlighting it and clicking the code button. I've fixed it for you this time.
Answer by asimov · Jun 26, 2012 at 05:30 PM
You can turn off its renderer, like this;
clonedBullet.renderer.enabled = false;
If you're using a prefab, its probably best to have the renderer disabled to begin with (by unchecking the box in Inspector) and then enable it once you have Instantiated it.
clonedBullet.renderer.enabled = true;
Another way is to fire an empty object and Instantiate the prefab at its current position after firing.
Sure there are many others that create the same affect.
Hope that helps.
Your answer
Follow this Question
Related Questions
how to make a first person controller shooting a target? 0 Answers
Unity3D Ai wont shoot 1 Answer
Help with reloading gun. 1 Answer
Need help... Start Button no longer working!!!!! 0 Answers
Shooting Pistol and Machine Gun 2 Answers