Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by AlphaBigWood · Oct 15, 2016 at 06:20 AM · instantiateinstantiate prefabspace shooter

UNITY 5 - SPACE SHOOTER - INSTANTIATE NOT SPAWNING

Hi Everyone, new here.

Bolts Instantiates in space shooter won't spawn, even though my code is EXACTLY the same as in the video script and change log doesn't mention any change between unity 5 and previous version for this part.

It won't spawn, let alone be spawned through get.button..

just started coding, already getting frustrated hehe !

Hope someone will help,

Thank you !

Comment
Add comment · Show 7
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 AlphaBigWood · Oct 15, 2016 at 01:54 AM 1
Share

Ok, after trying many alternatives, i found the problem and the solution so i'll just post it here for future users who might encounter this problem :

Don't write the code inside " void Update() " as shown in the video, for some reason it does compile but it's like when you run the game, it goes past this command.

Write it with the rest under "void Fixedupdate()" !

$$anonymous$$oderators : you should make this part of the changelog ;)

$$anonymous$$indly,

BigWood !

avatar image joelyde AlphaBigWood · Oct 20, 2016 at 01:54 PM 0
Share

Thanks! Had the same issue.

avatar image Kossuranta AlphaBigWood · Oct 20, 2016 at 02:15 PM 0
Share

That really isn't proper fix as in FixedUpdate there is a chance that game doesn't register your button press at all. I can't imagine any reason why it wouldn't work in Update. By any chance could you paste code where it doesn't work inside Update().

avatar image eitanwass · Oct 20, 2016 at 02:36 PM 0
Share

Paste the code.... Putting it in FixedUpdate() isn't a solution.

avatar image Naphier · Oct 21, 2016 at 03:10 AM 0
Share

Need to see your code in order to help you.

avatar image Dracodarkheart · Jan 26, 2017 at 08:13 AM 0
Share

same having same problem

avatar image hassanyawar · Jan 26, 2017 at 11:23 AM 0
Share

Please post your code. Putting the code in FixedUpdate() isn't a proper fix.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AceWeston · Mar 07, 2017 at 04:26 PM

I have the same issue. Shots are spawned (I can see them in the hiearchy, and the position is changing) but they do not show in the game view. If i just drag and drop a shot into the game hierarchy it shows as intended though.

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class Boundary {
     public float xMin, xMax, zMin, zMax;
 };
 
 public class PlayerController : MonoBehaviour {
 
     private Rigidbody rb;
 
     public float speed;
     public float tilt;
     public Boundary boundary;
 
     public GameObject shot;
     public Transform shotSpawn;
     public float fireRate;
 
     private float nextFire;
 
     void Start(){
         rb = GetComponent<Rigidbody> (); 
     }
 
     void Update () {
 
         if (Input.GetButton("Fire1") && Time.time > nextFire){
             nextFire = Time.time + fireRate;
 
             Instantiate(shot, shotSpawn.position , shotSpawn.rotation);
 
         }
     }
 
     void FixedUpdate () {
         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
 
         rb.velocity = new Vector3 (moveHorizontal, 0.0f, moveVertical) * speed;
 
         rb.position = new Vector3 (
             Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
             0.0f,
             Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
         );
 
         rb.rotation = Quaternion.Euler (0, 0, rb.velocity.x * -tilt);
     } 
 }
 

Shot uses Mover script:

 using UnityEngine;
 using System.Collections;
 
 public class Mover : MonoBehaviour {
 
     private Rigidbody rb;
     public float speed;
 
     void Start() {
         rb = GetComponent<Rigidbody> ();
         rb.velocity = new Vector3 (0.0f, 0.0f, 1.0f) * speed;
     }
 }
 

EDIT Seems like I've got it to work. I had set the x rotation on the on the shot quad to 90 but not the x rotation on the shot spawn. PING @AlphaBigWood

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 nmarcora · Sep 03, 2017 at 05:30 PM 0
Share

Thank you, @AceWeston! I was having the exact same problem and this solved it. :)

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

11 People are following this question.

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

Related Questions

Projectiles trigger affecting other projectiles of same prefab - C# 0 Answers

Object created through Instantiate does not update its position at the first frame 1 Answer

Animation doesn't affect the new instantiated object. 0 Answers

Why is it important to create an empty gameobject for my prefabs? 0 Answers

Instanciate prefab responsively 1 Answer


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