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 HasnainKhan · Jan 19, 2017 at 04:33 PM · movement scriptmove an objectselecting objects

Move a selected object.

Currently i am working on an RTS game and I want to select an object and then move that selected object but the problem is when i click somewhere in the terrain then all gameobjects began to move to that point . So how i can achieve this . And my code is this. Any help will be appreciated . Thanks.

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class OnMouseMove : MonoBehaviour { GameObject obj; %|-1720431080_2|% %|746481839_3|% %|-1051463637_4|% %|-1988011646_5|% %|2050251650_6|% void Start() { %|783189557_9|% ismove = false; } %|1837895370_12|% void Update() { %|-1673666550_15|% %|-1029015290_16|% Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); %|-764338503_18|% if (Physics.Raycast(ray, out hit)) { obj = hit.collider.gameObject; } %|1616007807_23|% if (Input.GetMouseButton(0)) { %|-1342988185_26|% } else if (ismove) { %|610140773_30|% %|1993733279_31|% %|1503594703_32|% void Set_Target_Positoion() { %|-1926264001_35|% RaycastHit hit; if (Physics.Raycast(ray, out hit)) %|-577530960_38|% TargetPosition = hit.point; %|906981630_40|% ismove = true; } void MovePlayer(GameObject obj) %|1722478830_44|% %|148729395_45|% %|785444710_46|% %|1751700689_47|% %|-579865991_48|% %|-85349588_49|% %|1369942042_50|% %|-1020095342_51|% }

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 HenryStrattonFW · Jan 19, 2017 at 09:07 PM 0
Share

There appears to have been some sort of terrible copy-paste accident with the code you've posted, I'd suggest editing the post and trying to post the code again as this is currently unreadable.

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Teleporting 2D object once 1 Answer

Moving moving Object with left/right arrow keys in a circular direction 3 Answers

How to control how far a character can jump 0 Answers

My character doesn't move. How should I do? 1 Answer

How to make an object not move through an wall using transform.translate? 3 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