- Home /
UnityEngine.Component.audio' is a `property' but a `type' was expected
In the tutorial of space shooter i saw there the teacher use audio.Play. But i try that and i got error, then i use private AudioSource audioSource;
void Awake()
{
audioSource = GetComponent<AudioSource>();
}
This method but it still getting error called :UnityEngine.Component.audio' is a property' but a
type' was expected .
please solve please , here is my code.........
using System.Collections; using System.Collections.Generic; using UnityEngine; [System.Serializable] public class Boundary { public float xMin, xMax, zMin, zMax; }
public class PlayerController: MonoBehaviour { public float speed; public float tilt; private Rigidbody rb; public Boundary boundary; public GameObject shot; public Transform shotSpawn; public float fireRate;
private audio au;
private float nextFire;
void Start ()
{
rb = GetComponent<Rigidbody> ();
au = GetComponent<audio>();
}
void Update ()
{
if (Input.GetButton ("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Instantiate (shot, shotSpawn.position, shotSpawn.rotation);
au.Play ();
}
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal,0.0f,moveVertical);
rb.velocity = movement * speed;
rb.position = new Vector3
(
Mathf.Clamp (rb.position.x,boundary.xMin,boundary.xMax),
0.0f,
Mathf.Clamp (rb.position.z,boundary.zMin,boundary.zMax)
);
rb.rotation = Quaternion.Euler (0.0f,0.0f, rb.velocity.x * -tilt);
}
}
It's telling you the problem: audio
is an inherited, deprecated property for $$anonymous$$onobehavior types. You need to replace audio
with AudioSource
.