- Home /
 
               Question by 
               Chocolade · Oct 22, 2016 at 08:56 AM · 
                c#scripting problemscript.  
              
 
              How do i make the player to walk to where the mouse cursor position was clicked ?
This is working but the problem is that the player is not walking to there but it's just jumping to there. I want to make the player to walk to the place not to place there. I guess i should use somehow animator and the walk state ?
This is script i'm using now:
 using UnityEngine;
 using System.Collections;
 
 public class MovePlayer : MonoBehaviour {
 
     Vector3 newPosition;
 
     void Start()
     {
         newPosition = transform.position;
     }
 
     void Update()
     {
         if (Input.GetMouseButtonDown (0)) 
         {
             RaycastHit hit;
             Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
             if (Physics.Raycast (ray, out hit)) 
             {
                 newPosition = hit.point;
                 transform.position = newPosition;
             }
         }
     }
 }
 
               Comment
              
 
               
              Sometimes, I wonder if people starting with Unity watch the official Unity tutorials ....
https://www.youtube.com/watch?v=b$$anonymous$$3CXzj5x$$anonymous$$4
Your answer
 
 
             Follow this Question
Related Questions
How can I call the Load method and/or the ShootingSettings method also only once in the Update ? 1 Answer
How can i check and fire an event when the user look at specific object ? 0 Answers
How can I animate linerenderer lines over time ? 1 Answer
How do i use a public sealed class to create objects and destroy them ? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                