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 robbos729 · Dec 05, 2018 at 08:31 AM · 2d2d gameappspawner

when I click a button I want it to move to one of my spawners

When I click my button I want it to go to a random one of my 21 spawners on my canvas.

Thanks in advance

Comment
Add comment · Show 5
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 fmarianacci · Dec 05, 2018 at 02:47 PM 0
Share

I don't really understand what you want, the button is in the inspector or in the canvas ? The spawner are in the world or in the canvas ? Do you want to move the editor camera or a camera in the game ? Or you want to position the spawner somewhere in the scene ?

I guess this can help you, but who knows ^^ https://answers.unity.com/questions/942869/move-scene-camera-to-gameobject-via-editor-script.html

avatar image robbos729 · Dec 05, 2018 at 08:01 PM 0
Share

@fmarianacci Basically in the canvas I have all my stuff and I just want my button to reposition when you tap it it’s all in the canvas and I don’t want anything else to move just the button to one of my 21 spawners thanks

avatar image fmarianacci robbos729 · Dec 06, 2018 at 07:34 AM 0
Share

Any screenshot of what you need may help me to understand :)

avatar image robbos729 · Dec 06, 2018 at 05:44 PM 0
Share

alt text

@fmarianacci the 21 spawners are the things i want to relocate to when i tap the tile (button as called in the game) But i want it to be a random one :)

unity.jpg (221.4 kB)
avatar image robbos729 · Dec 09, 2018 at 10:39 AM 0
Share

Does that help @fmarianacci

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by leftshoe18 · Dec 09, 2018 at 01:53 PM

Create a method that moves the button and make sure it's public:

 public void MoveButton()
     {
         int rand = Random.Range(0, spawnerArray.Length)
     
         button.transform.position = spawnerArray[rand].transform.position;
     }

Then assign this method to the OnClick() property of your button.

Comment
Add comment · Show 4 · 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 robbos729 · Dec 09, 2018 at 01:58 PM 0
Share

Just to make sure my spawners are just empty objects that I have called spawner so do I have to add code to make the empty object a spawner

avatar image robbos729 · Dec 09, 2018 at 02:42 PM 0
Share

alt text

alt text

they are the only two issues (i am new to coding)

button.png (89.5 kB)
spawner-array.png (88.7 kB)
avatar image leftshoe18 robbos729 · Dec 09, 2018 at 10:09 PM 0
Share

Apply the script to your container of spawner objects. I would store them as a Transform or GameObject array.

Full script:

 using UnityEngine;
 
 public class SpawnController : $$anonymous$$onobehaviour
 
 {
     // put all your spawner items in here
     [SerializeField] Transform[] spawnerArray;
 
      public void $$anonymous$$oveButton()
      {
          int rand = Random.Range(0, spawnerArray.Length)
      
          button.transform.position = spawnerArray[rand].position;
      }
 }
avatar image robbos729 leftshoe18 · Dec 09, 2018 at 10:11 PM 1
Share

Thank you so much

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

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

Related Questions

2d look at workaround creates jitter 0 Answers

Get object to follow line created by trail renderer 1 Answer

Destroy script turns objects into ghosts 2 Answers

How to check if an object hits the ground hard enough then add explosive force around it (2D) 1 Answer

Instantiate a GameObject with a specific Z rotation 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