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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章