не работает audio.PlayOneShot
Ошибка:
NullReferenceException: Object reference not set to an instance of an object PlayerMove.Update () (at Assets/Script/PlayerMove.cs:29)
Скрипт управления персонажем:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
public class PlayerMove : MonoBehaviour {
public float speed;
private Vector3 dir;
public AudioClip impact;
AudioSource audio;
// Use this for initialization
void Start () {
dir = Vector3.zero;
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
speed=20;
if (dir==Vector3.forward)
{
dir=Vector3.left;
audio.PlayOneShot(impact, 0.7F);
}
else
{
dir=Vector3.forward;
}
}
float amoutToMove = speed*Time.deltaTime;
transform.Translate(dir*amoutToMove);
}
}