unity3d 基础 2017.9.17

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" ) );

}


else if( Input.GetKey( KeyCode.LeftArrow ) )
{
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米

float translation = Time.deltaTime * 10;
transform.Translate(0, 0, translation);
}
}

 

发布了31 篇原创文章 · 获赞 2 · 访问量 9208
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章