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
1
Question by Zukas · Dec 19, 2013 at 05:43 PM · newbievector2click to move

How to retrieve GameObject's Vector2 coordinate and move another object to it's place

So, I'm trying to make script detect GameObject's coordinate/vector2 and then use it to move to it's spot. So those GameObject's are like nodes to which you can travel. This is how my script looks so far, I think it will explain what I want it to be like, and I know that it's wrong but I believe you'll get the point.

 using UnityEngine;
 using System.Collections;
 
 public class WorldMapMovement : MonoBehaviour
 {
     public float smooth;
     public GameObject Town1;
     public GameObject Town2;
 
     private Vector2 travelPosition;
 
     void Awake ()
     {
         travelPosition = transform.position;
         Town1 = GameObject.Find("Town1");
         Town2 = GameObject.Find("Town2");
     }
 
     void Update ()
     {
         TravelChanging();
     }
 
     void TravelChanging ()
     {
         Vector2 positionA = Vector2(Town1);
         Vector2 positionB = Vector2(Town2);
 
         if(Input.GetKeyDown(KeyCode.Q))
             travelPosition = positionA;
         if(Input.GetKeyDown(KeyCode.E))
             travelPosition = positionB;
 
         transform.position = Vector2.Lerp(transform.position, travelPosition, smooth * Time.deltaTime);
 }
 

Thanks in advance! Zukas.

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 Sundar · Dec 19, 2013 at 06:27 PM 0
Share

you must be getting errors here - Vector2 positionA = Vector2(Town1);

1 Reply

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

Answer by highpockets · Dec 19, 2013 at 07:02 PM

Generally you should use smaller case on the first letter of the first word of a variable.. Town1 should be town1. That's up to you though. Under the TravelChanging function switch the first 2 lines to:

Vector2 positionA = town1.transform.position

Vector2 positionB = town2.transform.position

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 Zukas · Dec 19, 2013 at 08:12 PM 1
Share

Thanks! It solved it. I don't know how to exactly confirm this answer. It says I need 15 reputation or something.

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

20 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

Related Questions

Multiple Cars not working 1 Answer

I need help !!! -3 Answers

How would I get camera bobbing? 0 Answers

Click To Revert to Original Texture else Destroy script help 1 Answer

How to have animation play correctly 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