using System.Collections; using System.Collections.Generic; using UnityEngine; public class AudioController : MonoBehaviour { private AudioSource ads; // Start is called before the first frame update void Start() { ads=this.GetComponent<AudioSource>(); } // Update is called once per frame void OnGUI() { if (GUILayout.Button("play")) { if (!ads.isPlaying) { ads.Play(); } } if (GUILayout.Button("stop")) { if (ads.isPlaying) { ads.Stop(); } } } }
//移动控制
using UnityEngine;
using System.Collections;
public class player:MonoBehaviour{
public float speed=5f;
public float rotationSpeed=3f;
private Rigidbody rigidbody;
void Start(){
rigidbody=this.GetComponent<Rigidbody>();
}
void FixedUpdate(){
float h=Input.GetAxis("Mouse X");
float v=Input.GetAxis("Vertical");
rigidbody.velocity=transform.forward*v*speed;
rigidbody.angularVelocity=transform.up*h*rotationSpeed;
}
}
//控制门
void OnTriggerEnter(Collider collider){
if(collider.tag=="player"){
transform.position=new Vector3(transform.position.x,transform.position.y+3.6f,transform.position.z);
}
}
//播放声音
private AudioSource audioSource;
audioSource=this.GetComponent<AudioSource>();
audioSource.Play();
using UnityEngine; using System.Collections; public class AudioController:MonoBehaviour{ private AudioSource ads; void Start(){ ads=this.GetComponent<AudioSource>(); } void OnGUI(){ if(GUILayout.Button("play")){ if(!ads.isPlaying) ads.Play(); } } }