Home > other >  Unity3d person move
Unity3d person move

Time:09-21

Mobile I use the mouse to click on the ground, is a person move to click on the location, the problem is that when I click on the ground around quickly, double characters appear, I want to ask the great spirit what caused this problem and what is the solution?



Below is my mobile code:
Using System. The Collections;
using System.Collections.Generic;
using UnityEngine;

Public class playerMove: MonoBehaviour
{
Public Transform myTransform;
Private Ray Ray;
Private RaycastHit mHit;
//whether the switch action
Private bool isCanAutoMove;
Private Vector3 mTargetPos;

Public Animator myAnimator;
Private Camera _myCamera=null;
Public float movespeed=5 f;

Void the Start ()
{
MyTransform=gameObject. GetComponent (a);
_myCamera=Camera. The main;
MyAnimator=GetComponent (a);

}
Void the Update ()
{
//mouse click on a certain point, people to the site
If (Input. GetMouseButton (0))
{
//return a Ray Ray from the camera to the screen the specified point
Ray Ray=_myCamera. ScreenPointToRay (Input. MousePosition);
If (Physics. Raycast (ray, out mHit))
{
If (mHit starts. GameObject. Tag=="plane")
{
MTargetPos=mHit. Point;
Transform. LookAt (new Vector3 (mTargetPos. X, mTargetPos. J y, mTargetPos. Z));
IsCanAutoMove=true;
}
}
}
If (isCanAutoMove)
{

IdelOrRun myAnimator. SetBool (" ", true);
The transform. Translate (Vector3. Movespeed forward * * Time. DeltaTime);
MyTransform. Transform. Translate (Vector3. Movespeed forward * * Time. DeltaTime);
Float short=Vector3. Short (mTargetPos, transform the position);
If (short & lt;=0.5 f)
{
IsCanAutoMove=false;
MyAnimator. SetBool (" IdelOrRun ", false);
}
}
}
}

CodePudding user response:

Unity automatically NavMesh pathfinding function

CodePudding user response:

Well, can you more clearly, which means I did not use the NavMesh, but unity will automatically call?

CodePudding user response:

Ghosting is the camera problem, you take a closer look at the camera this

CodePudding user response:

Don't set the camera's Clear Flags for Dont Clear
  • Related