- Home /
Help with weapon changing problems...
I have an empty game object called: Weapons which contains my Rocket Launcher and Bazooka where I shoot from.
I have attached a shooting script with buttons so that on click they shoot. I also have a input key down change weapons.
Because I put my shooting script on the weapon game object the projectiles come out the same place.
I want to have the buttons shoot differently from the root. The problem is that if I have seperate scripts on seperate weapons I would need seperate buttons.
How would I use same (shooting) buttons to shoot from varying places on different weapons and with different projectiles?
Answer by _Petroz · Jul 07, 2010 at 03:30 AM
Create public members in the weapon script class:
Vector3 projectileSpawnOffset;
GameObject projectilePrefab;
Then use those variables when instantiating the projectile in the common shoot code.
Could you be more specific by posting an example so I know where to put the code and how to use it? Thanks.
Assu$$anonymous$$g you're using the Instantiate function to create the projectiles the code would be something like:
projectilePosition = weapon.transform.TransformPoint(projectileSpawnOffset); Instantiate(weapon.projectilePrefab, projectilePosition, Quaternion.identity);
Your answer
Follow this Question
Related Questions
Making an object rotate towards touch 3 Answers
How to make UI Button Fire Continuously ? 3 Answers
How can I have multiple shoot buttons? 1 Answer
Shoot when GUI is pressed? 0 Answers