1、角色转换方向 使用transform.localScale
// 借鉴于character controller2d 中的demo
if( Input.GetKey( KeyCode.RightArrow ) )
{if( transform.localScale.x < 0f ) //按右键 如果角色向左 则换位置
transform.localScale = new Vector3( -transform.localScale.x, transform.localScale.y, transform.localScale.z );
if( _controller.isGrounded )
_animator.Play( Animator.StringToHash( "Run" ) );}
{
if( transform.localScale.x > 0f ) // 按左键 如果角色向右 则换位置
transform.localScale = new Vector3( -transform.localScale.x, transform.localScale.y, transform.localScale.z );
if( _controller.isGrounded )
_animator.Play( Animator.StringToHash( "Run" ) );
}
2、在demo中 看到 Time.deltaTime *speed
应该是在帧中换成每秒运动距离吧。。。
如果不相乘就是每帧运动多少。。。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void Update() {
// Move the object 10 meters per second!
//每秒移动物体10米
transform.Translate(0, 0, translation);
}
}