Space Shooter教程笔记

1、Mathf.Clamp
设置指定参数数值的范围,在最大值和最小值之间。

public static float Clamp(float value, float min, float max)
Description
Clamps a value between a minimum float and maximum float value.

using UnityEngine;using System.Collections;
public class ExampleClass :MonoBehaviour{   
    void Update() {       
    transform.position = new Vector3(Mathf.Clamp(Time.time, 1.0F, 3.0F), 0, 0);   
     }
}

public static int Clamp(int value, int min, int max);
Description
Clamps value between min and max and returns value.

// Clamps the value 10 to be between 1 and 3.
// prints 3 to the console
Debug.Log(Mathf.Clamp(10, 1, 3));

2、定义一个公共调用类并序列化

公共类之前要注意做序列化[System.Serializable]

[System.Serializable]
public class Boundary 

{
    public float xMin, xMax, zMin, zMax;
}

调用时:
先声明public Boundary boundary; 再调用boundary.xMin

3、用欧拉角来改变刚体旋转角度

rigidbody.rotation = Quaternion.Euler(0.0f,0.0f,rigidbody.velocity.x * tilt);

4、协同程序StartCoroutine

yield return new WaitForSeconds(time)

这给方法就是让代码等待一定时间,这是个协同程序,可以让游戏不暂停的同时,让代码暂停.

using UnityEngine;using System.Collections;

public class WaitForSecondsExample :MonoBehaviour{      
void Start() {        
StartCoroutine(Example());   

 }       

 IEnumerator Example() {       
     print(Time.time);        
     yield return new WaitForSeconds(5);       
     print(Time.time);   
}   
}

你可能感兴趣的:(Space Shooter教程笔记)