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 slamancusa · Nov 12, 2016 at 12:30 PM · gameobjecttransform

How to Change Position of a GameObject to another GameObject C#

I am trying to create a game, or simulation rather where you walk around the room and collect cubes. When you "collect" one by walking into it, it will up your score by one and move the pickup to a different location within the room. In order to keep the cube in the room, I randomized the new transform by creating a series of reference points nearby and setting the transform equal to one of those.

 // Use this for initialization
 void Start ()
 {
     References.Add(Reference);
     References.Add(Reference1);
     References.Add(Reference2);
     References.Add(Reference3);
     References.Add(Reference4);
     References.Add(Reference5);
     References.Add(Reference6);
     References.Add(Reference7);
     References.Add(Reference8);
     References.Add(Reference9);
     References.Add(Reference10);
     References.Add(Reference11);
 }
 
 // Update is called once per frame
 void Update () {
 
 }

 void OnTriggerEnter(Collider other)
 {
     if(other.gameObject.CompareTag("PickUp"))
     {
         other.gameObject.transform.position = References[Random.Range(0, References.Count)].transform.position;
     }
 }

}

You'll see, I created a list, added my twelve reference gameObjects to the list, then when you collide with the pickup, it is supposed to transport to another one of them at random but it doesn't. The player just clips through the pickup. Any help with this is appreciated, and I am relatively new with unity so apologies for any mistakes in code formatting, or inefficiencies.

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 Glurth · Nov 12, 2016 at 07:49 PM 0
Share

I don't see any problems. First step would be to confirm the code is actually being executed. Stick a Debug.Log("Pickup"); line, inside the if statement, to confirm the code flows as expected. You can also use this command to display various positional values, what object is randomly selected, etc...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by slamancusa · Nov 12, 2016 at 08:05 PM

Hm, thanks for the reply. I'm currently away from my computer until later tommorow but i will be sure to test what you've said. For reference, what if the code is not being executed as expected? Are there any immediate fixes or is it just a matter of troubleshooting? @Glurth

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

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

Related Questions

Assets/CArSmoothFollow.cs(40,68): error CS0246: The type or namespace name `ExampleGame_Game' could not be found. 1 Answer

Operator '==' is ambiguous on operands of type 'Vector2' and 'Vector3' 1 Answer

Auto level an object 0 Answers

Instantiated objects can't convert to GameObjects 0 Answers

NullException Error while instantiating gameobjects 0 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