1, create scenes, add roles such as
2, add a script under the role
3, fill in the logic
Using Unityengine;
Using System.Collections;
public class Playermovement:monobehaviour
{
public float speed = 6f;
Vector3 movement;
Rigidbody Playerrididbody;
void Awake () {
Playerrididbody = getcomponent<rigidbody> ();
}
void Fixedupdate () {
Float h = input.getaxisraw ("horizontal");
Float v = input.getaxisraw ("Vertical");
Move (h, v); Enable player to move
}
void Move (float h, float v) {
Movement. Set (H, 0f, V); Set movement ' s value
Movement = movement.normalized * speed * time.deltatime;
Playerrididbody.moveposition (transform.position + movement); Let the protagonist move through the Moveposition () method
}
}
4, run, use up and down keys to move around
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Unity3d 5.0 Survivalshooter (a) character movement