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 /
  • Help Room /
avatar image
0
Question by ZhaWarudo · Sep 16, 2015 at 11:43 PM · c#instantiateballlaunchpong

Update instatiate doesn't work?

I have 4 empty game objects from which to launch balls ( like Crash Bash Ballistix )but after the first ball is launched ( Start ) nothing happens. It works if i attach 4 scripts to these objects but that's lame and I want it all in one while attached to some other object like arena.

public Rigidbody Ball;

 private float Timer = 0;

 private Rigidbody newBall = null;

 public GameObject Launch1;
 public GameObject Launch2;
 public GameObject Launch3;
 public GameObject Launch4;

 void Start () {



     newBall = Instantiate(Ball, Launch1.transform.position, transform.rotation) as Rigidbody;
     newBall.AddForce (new Vector3 (-220, 0, -150));

 }

 void Update() 
 

{

     Timer += Time.deltaTime;

     if (Timer == 40) {
         newBall = Instantiate (Ball, Launch1.transform.position, transform.rotation) as Rigidbody;
         newBall.AddForce (new Vector3 (-22, 0, -15));
         Timer = 0;


     }

     else if (Timer == 30) {
         newBall = Instantiate (Ball, Launch2.transform.position, transform.rotation) as Rigidbody;
         newBall.AddForce (new Vector3 (-22, 0, -15));

     }

     else if (Timer == 20) {
         newBall = Instantiate (Ball, Launch3.transform.position, transform.rotation) as Rigidbody;
         newBall.AddForce (new Vector3 (-22, 0, -15));
     }

     else if (Timer == 10) {
         newBall = Instantiate (Ball, Launch4.transform.position, transform.rotation) as Rigidbody;
         newBall.AddForce (new Vector3 (-22, 0, -15));
         Debug.Log ("YOLO");
     }


}
}

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 Rostam24 · Sep 17, 2015 at 07:48 AM 0
Share

It probably has to do with time being a float, and you checking if a float value is the same as an int value. It's probably better if you check if time is bigger than 10, and if so instantiate and then reset time. Also, consider pooling: instantiating everything you need in Awake(), but in a disabled state. Then simply enable them when you need them.

1 Reply

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

Answer by hexagonius · Sep 17, 2015 at 08:33 AM

I agree with Rostam24. check for the time being greater then a reference value.if so, instantiate and reset time. change the reference value if you must, either by Random value or values in a list or just continuously adding or subtracting... whatever the case.

If your not in mobile, pooling might be too much an effort and also probably an advanced technique for you.

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

I got Some Error about how to Transform Postiton Enemy where one point can spawn 2 enemies. 1 Answer

How does one continuously move an object forward without using velocity? 1 Answer

Adding different values to randomly created objects 0 Answers

Need a variable to exist in the current context - not sure where to start 0 Answers

While instantiating getting object reference not set for no reason? 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