- Home /
How to change 3rd shooter directions?
HI I'm making a 2d side-scorlling game now.I'd like to make a shooter function. The shooting direction is the same of my character,however,the script only is able to shoot in one specific direction... Moreover,I'd like to destroy "enemy" objects after collision,I used collision script,but it didn't work. Here are my script: var prefebmoney:Transform; var power: float;
function Update () { if (Input.GetKeyDown (KeyCode.Z)) var instancemoney = Instantiate(prefebmoney,transform.position,transform.rotation); instancemoney.rigidbody.velocity =transform.right*power; }
How can I modify my script?Thank you
I'm confused on a couple of things; You say you want a "shooter function" which I assume means you want your character to be able to shoot. I understood that one. Then you have a prefabmoney
and instancemoney
which is where you lost me.
also cleaning up your whitespace and only putting one statement per line will really help with readability.
When you say "change directions" you mean you want to be able to face left and right? or face left and right and up and down and all the angles in-between?
Hi I'd like to make myself clearer.The script is which i found online,it is only able to shoot in a specific direction,and I'd like to make a shooter function: 1.the shooting direction is the same as charater's facing direction 2.After it collision into the objects which is tagged "enemy",destroy gameobject.
I tried this script plus collision script,but they didn't work... thx to reply!
I also tried to use animation to work this function out,I'd like to play a shooting animation after pressing Z key,and destroy enemy objects after collision.But the animation keeps playings all the time. Here is my script:
var Sphere : GameObject;
function Start(){ animation.Stop("shooter");}
function Update () { if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Z)) Sphere = GameObject.FindWithTag("Enemy"); animation.Play("shooter");
var hit : RaycastHit; var ray= transform.TransformDirection (Vector3.right);
if(Physics.Raycast(transform.position,ray,1)){ Destroy(Sphere.gameObject);
}}
How can I fix it?
Your answer
Follow this Question
Related Questions
How do I make a raycast for a particle 1 Answer
Bouncy platforms/spring jump? 4 Answers
How to Debug in a standalone build? 4 Answers
Where is the FPS Tutorial? 1 Answer
trigger collision with three triggers help -1 Answers