using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
public GameManager manager;
public float moveSpeed;
public GameObject deathParticles;
private float maxSpeed = 5f;
private Vector3 input;
private Vector3 spawn;
public AudioClip[] audioClip;
public Rigidbody myRigidbody { get; private set; }
// Use this for initialization
void Start ()
{
spawn = transform.position;
manager = manager.GetComponent<GameManager>();
this.myRigidbody = this.GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
input = new Vector3(Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));
if (myRigidbody.velocity.magnitude < maxSpeed)
{
myRigidbody.AddRelativeForce(input * moveSpeed);
}
if (transform.position.y < -2)
{
Die();
}
}
void OnCollisionEnter(Collision Other)
{
if (Other.transform.tag == "Enemy")
{
Die();
}
}
void OnTriggerEnter(Collider other)
{
if (other.transform.tag == "Enemy")
{
Die();
}
if (other.transform.tag == "Token")
{
manager.tokenCount += 1;
PlaySound(0);
Destroy(other.gameObject);
}
if (other.transform.tag == "Goal")
{
manager.CompleteLevel();
PlaySound(1);
}
}
void PlaySound(int clip)
{
audio.clip = audioClip[clip];
audio.Play();
}
void Die()
{
Instantiate(deathParticles, transform.position, Quaternion.Euler(270, 0, 0));
transform.position = spawn;
}
}
The Code Problem
void PlaySound(int clip)
{
audio.clip = audioClip[clip];
audio.Play();
}
“audio.clip” and “audio.Play();”
Unity Error;
Error 1 ‘UnityEngine.Component’ does not contain a definition for ‘clip’ and no extension method ‘clip’ accepting a first argument of type ‘UnityEngine.Component’ could be found (are you missing a using directive or an assembly reference?)
Error 2 ‘UnityEngine.Component’ does not contain a definition for ‘Play’ and no extension method ‘Play’ accepting a first argument of type ‘UnityEngine.Component’ could be found (are you missing a using directive or an assembly reference?)
Help me Pls