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
0
Question by Aladine · Aug 24, 2013 at 01:54 PM · randomprefabs

Why "random" give same values to all prefabs ?

Hello everyone, am sure this is a very ridiculous issue but i couldn't figure out how to solve it, #the objective is this ;
-when 2 prefabs collide, each one of them go to a random position #how am i trying to do it ? void OnTriggerEnter (Collider collider) { if (collider.gameObject.CompareTag ("stand_enemy")) { hit = true; tmpTarget = new Vector3 (Random.Range (-10, 10), Random.Range (-5, 5), 0); Debug.Log (gameObject.name + ": " + targetPosition);

         }
     }

so this is suppose to assign a random Vector3 to the tmpTarget variable, however in the Debug line, the result is the same for each 2 collided prefabs, i tried to do this but also same result : gameObject.GetComponent ().tmpTarget = new Vector3 (Random.Range (-10, 10), Random.Range (-5, 5), 0);

thank you very much for your help, have a nice day

UPDATE: Full class to better understand the problem : UPDATE2: pastbin link for better visualization

Comment
Add comment · Show 8
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 meat5000 ♦ · Aug 24, 2013 at 01:59 PM 0
Share

how does tempTarget relate to targetPosition?

avatar image Aladine · Aug 24, 2013 at 02:12 PM 0
Share

i thought that wasn't necessary, i updated the topic, thank your for replying

avatar image fafase · Aug 24, 2013 at 02:19 PM 0
Share

And you do see different names for the printing of the game object in the Log?

avatar image Aladine · Aug 24, 2013 at 02:24 PM 0
Share

@fafase yes

avatar image meat5000 ♦ · Aug 24, 2013 at 02:30 PM 0
Share

Put the name of the script into GetComponent (SCRIPT) which contains the tmpTarget you are trying to retrieve/update. You haven't posted the code to show us what you actually DO with tmpTarget to make it update the positions.

Show more comments

1 Reply

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

Answer by meat5000 · Aug 24, 2013 at 03:02 PM

Your debug will say:

 targetPosition=Vector3.MoveTowards(targetPosition,shipControl.myTransform.position, speed * Time.deltaTime);

As the debug is inside an enter function which will only execute once on enter. hit = true; and targetPosition gets updated but debug is not called again as the Collision function is not entered into again until next collision.

It should show differently after multiple enemy collisions.

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

16 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Memory Game Question 1 Answer

Spawn A Random Prefab 2 Answers

How would I go about making random car prefabs drive up and down a road at varying speeds? (for example, crossy road) 1 Answer

Random platform spawning with current code? 0 Answers

instantiate a prefab from array and then changing it 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