【喷火】 public GameObject Huomiao;
public GameObject Huomiao1;
void Update () {
GameObject obj = GameObject.FindWithTag("Huomiao1");
if (Input.GetKeyDown(KeyCode.W))
{
Huomiao.SetActive(true);
Huomiao1.SetActive(true);
}
if (Input.GetKeyUp(KeyCode.W))
{
Huomiao.SetActive(false);
Huomiao1.SetActive(false);
}
if (Input.GetKeyDown(KeyCode.S))
{
Huomiao.SetActive(true);
Huomiao1.SetActive(true);
}
if (Input.GetKeyUp(KeyCode.S))
{
Huomiao.SetActive(false);
Huomiao1.SetActive(false);
}
【射击】
public class Sheji : MonoBehaviour {
void Update () {
if (Input.GetMouseButton(0))
{
transform.position += transform.forward * 30 * Time.deltaTime;
Destroy(gameObject,1f);
}
}
}
【轮子】
public class Lunzi : MonoBehaviour {
void Update () {
if (Input.GetKey(KeyCode.W))
{
transform.Rotate(new Vector3(0, -3, 0));
}
if (Input.GetKey(KeyCode.S))
{
transform.Rotate(new Vector3(0, 3, 0));
}
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(new Vector3(0, -2, 0));
transform.Rotate(new Vector3(0, 2, 0));
}
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(new Vector3(0, -2, 0));
}
if (Input.GetKey(KeyCode.D))
{
transform.Rotate(new Vector3(0, 2, 0));
transform.Rotate(new Vector3(0, -2, 0));
}
if (Input.GetKey(KeyCode.D))
{
transform.Rotate(new Vector3(0, -2, 0));
}
}
【相机跟踪】
public class Camcar : MonoBehaviour {
public Transform TankeTransform;
private Vector3 tanke;
void Start () {
tanke = transform.position - TankeTransform.position;
}
void Update () {
transform.position = TankeTransform.position + tanke;
}
}