Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Different · Aug 11, 2012 at 10:56 AM · javascriptshootingchanging

Shooting and changing bullet

Well, I'm trying to make 4 changeable bullets that will shoot properly forward in JS. I've tried everything, but It's still not working. Some tips what I should use? Bullets names: Fireball, Bubbleball, Snowball and a Waterball. Thanks

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image lozzaaa · Aug 11, 2012 at 11:44 AM 0
Share

What have you tried? What isn't working?

Do you make a prefab for each bullet type and then instantiate them at the end of the gun with a velocity co$$anonymous$$g out of it?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by aldonaletto · Aug 11, 2012 at 11:43 AM

What doesn't work as expected? The direction, the bullet selection? Anyway, I would add rigidibodies to the bullet prefabs, and define the prefabs in an array in the Inspector. To define the spawning position/rotation and direction, I would create an empty object "SpawnPoint", adjust its position and rotation and child it to the owner of the shooting script. Finally, would use a variable curBullet to show which bullet is currently selected:

var prefabs: GameObject[]; // assign the prefabs here in the Inspector var curBullet: int = 0; // select the current bullet here

private var spawnPoint: Transform; // defines the position/direction private var bulletSpeed: float = 20; // bullet speed

function Start(){ // find the spawn point once at Start: spawnPoint = transform.Find("SpawnPoint"); }

// shoot the bullet selected by the indx parameter:

function Shoot(indx: int){ var bullet: GameObject = Instantiate(prefabs[indx], spawnPoint.position, spawnPoint.rotation); bullet.rigidbody.velocity = spawnPoint.forward * bulletSpeed; Destroy(bullet, 5); // bullet self-destructs in 5 seconds }

function Update(){ if (Input.GetButtonDown("Fire1")){ // shot the current bullet Shoot(curBullet); } } Change curBullet to select a different bullet.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Different · Aug 13, 2012 at 06:21 AM 0
Share

Looking good, but it's showing now "NullReferenceException UnityEngine.Transform.get_position () (at C:/BuildAgent/work/300357e52574df36/Runtime/ExportGenerated/Editor/UnityEngineTransform.cs:19) Shooting.Shoot (Int32 indx) (at Assets/Scripts/Shooting.js:15) Shooting.Update () (at Assets/Scripts/Shooting.js:23)" $$anonymous$$aybe I'm putting this in the wrong place? Already tried on the player and the SpawnPoint. Every bullet has Rigidbody component.

Also, I wanted changing bullets directly in game with, for example, 1, 2 and 3 button. Thanks for helping anyway.

Newbie rage ;)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

rigidbody woe ? 1 Answer

Cube terrain with perlin noise 1 Answer

Click To Revert to Original Texture else Destroy script help 1 Answer

What is wrong with this script? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges