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|% }
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.
Your answer
Follow this Question
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