unity3d笔记基础-1
if(Input.GetKey(KeyCode.S))
{ };
if(Input.GetKeyUp(KeyCode.S))
{ };
Input.GetAxis("Horizontal") ;
Input.GetAxis("Vertical“) ;
根据刚体移动向量对刚体进行旋转
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -5);
InvokeRepeating 重复调用
function InvokeRepeating (methodName : string, time : float, repeatRate : float) : void
// 2秒后开始
// 每0.3秒发射一颗炮弹
InvokeRepeating("Fire", 2, 0.3F);
举例
public class example : MonoBehaviour {
public Rigidbody projectile;
void LaunchProjectile() {
Rigidbody instance = Instantiate(projectile);
instance.velocity = Random.insideUnitSphere * 5;
}
public void Awake() {
InvokeRepeating("LaunchProjectile", 2, 0.3F);
}
}
private Done_GameController gameController;
//获取对象实体” GameController”
GameObject gameControllerObject = GameObject.FindGameObjectWithTag("GameController");
//获取与实体绑定的C#脚本” Done_GameController”
gameController = gameControllerObject.GetComponent<Done_GameController>();
//调用脚本的公有方法
gameController.AddScore(scoreValue);
协同程序
IEnumerator Evade ()
{
yield return new WaitForSeconds (Random.Range (startWait.x, startWait.y));
while (true)
{
targetManeuver = Random.Range (1, dodge) * -Mathf.Sign (transform.position.x);
yield return new WaitForSeconds (Random.Range (maneuverTime.x, maneuverTime.y));
targetManeuver = 0;
yield return new WaitForSeconds (Random.Range (maneuverWait.x, maneuverWait.y));
}
}
gameObject.SendMessage("Die");
调用所有游戏脚本的Die函数
Screen.lockCursor 锁定光标

浙公网安备 33010602011771号