using UnityEngine;
using System.Collections;
public class Tank : MonoBehaviour
{
public float MoveSpeed;
//移动速度
public float RotaSpeed;
//旋转速度
public float B_Speed;
//炮弹的速度 public GameObject Bullet;
//要克隆的炮弹 public Transform TrGun;
public AudioSource AS_iShoot;
public AudioSource AS_BackGround;
[Range (0,1)]
public float volume;
public AudioClip QuQu;
void Start()
{ //播放背景音乐 AS_BackGround.Play();
//背景音乐变为循环播放 AS_BackGround.loop = true; }
void Update()
{
AS_BackGround.volume = volume;
transform.Translate(0, 0, Input.GetAxis("Vertical") * Time.deltaTime * MoveSpeed); transform.Rotate(0, Input.GetAxis("Horizontal") * Time.deltaTime * RotaSpeed, 0);
if (Input.GetMouseButtonDown(0))
{
GameObject tempB = Instantiate(Bullet, Bullet.transform.position, Bullet.transform.rotation) as GameObject;
tempB.SetActive(true);
tempB.GetComponent(RigidBody).velocity = TrGun.up * B_Speed; //tempB.GetComponent(RigidBody).AddForce(TrGun.up * B_Speed, ForceMode.Impulse); //tempB.GetComponent(RigidBody).AddForceAtPosition(TrGun.up*B_Speed,transform.position);
//tempB.GetComponent(RigidBody).AddExplosionForce(1000, );
//播放射击音效
AS_iShoot.Play();
}
if (Input .GetKeyDown (KeyCode .J ))
{
AS_BackGround.Pause();
}
if (Input .GetKeyDown (KeyCode .K ))
{
AS_BackGround.Play();
}
if (Input .GetKeyDown (KeyCode .L ))
{
AS_BackGround.Stop();
}
if (Input .GetKeyDown (KeyCode .H ))
{
AS_BackGround.Stop();
AS_BackGround.clip = QuQu;
AS_BackGround.Play();
}
}//end_Update