using System.Collections; using System.Collections.Generic; using UnityEngine; public class ExDes : MonoBehaviour { float time = 1.5f; // Use this for initialization void Start () { Destroy(this.gameObject, time); } // Update is called once per frame void Update () { } }
using System.Collections; using System.Collections.Generic; using UnityEngine; public class FollowTargt : MonoBehaviour { public Transform player1; public Transform player2; private Vector3 offset; private Camera camera; // Use this for initialization void Start () { offset = this.transform.position - (player1.position + player2.position) / 2; camera = this.GetComponent<Camera>(); } // Update is called once per frame void Update () { if(player1 == null || player2 == null) { return; } this.transform.position = (player1.position + player2.position) / 2 + offset; float distance = Vector3.Distance(player1.position, player2.position); float size = distance * 0.6f; camera.orthographicSize = size; } }
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class TankHealth : MonoBehaviour { public int health = 100; //生命值 public GameObject tankExplosion; public AudioClip tankExplosionAudio; // Use this for initialization void TankDamage() { if (health <= 0) { return; } health -= 10; if (health < 0) { AudioSource.PlayClipAtPoint(tankExplosionAudio, this.transform.position); Instantiate(tankExplosion, this.transform.position, transform.rotation); Destroy(this.gameObject); SceneManager.LoadScene(0); } } void Start () { } // Update is called once per frame void Update () { } }
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Explosion : MonoBehaviour { float time = 1.5f; // Use this for initialization void Start () { Destroy(this.gameObject, time); } // Update is called once per frame void Update () { } }
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ShellExeplosion : MonoBehaviour { public GameObject shellExplosion; private void OnTriggerEnter(Collider other) { GameObject.Instantiate(shellExplosion, transform.position, transform.rotation); GameObject.Destroy(this.gameObject); if(other.tag == "Tank") { other.SendMessage("TankDamage"); } } // Use this for initialization void Start () { } // Update is called once per frame void Update () { } }
using System.Collections; using System.Collections.Generic; using UnityEngine; public class TankMove : MonoBehaviour { public float speed = 5; //移動速度 public float angelSpeed = 5; //轉動速度 private Rigidbody rigidbody; public int number = 1; // Use this for initialization void Start () { rigidbody = this.GetComponent<Rigidbody>(); } private void FixedUpdate() { float v = Input.GetAxis("VerticalPlayer" + number); rigidbody.velocity = this.transform.forward * v * speed; //坦克速度 float h = Input.GetAxis("HorizontalPlayer" + number); rigidbody.angularVelocity = this.transform.up * h * angelSpeed; //繞y軸轉動 } // Update is called once per frame void Update () { } }