Hello to Everyone.I am working on a 2D Platform game and i have a problem.I have this code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
[RequireComponent (typeof(AudioSource))]
public class spawnDoor : MonoBehaviour {
public MovieTexture movie;
private AudioSource audio;
public Transform WhereToSpawn;
public GameObject door;
// Use this for initialization
void Start () {
GetComponent<RawImage> ().texture = movie as MovieTexture;
audio = GetComponent<AudioSource> ();
audio.clip = movie.audioClip;
movie.Play ();
audio.Play ();
}
// Update is called once per frame
void Awake () {
if (Input.GetKeyDown (KeyCode.Space) && movie.isPlaying) {
movie.Pause ();
} else if (Input.GetKeyDown (KeyCode.Space) && !movie.isPlaying) {
movie.Play ();
}
}
void OnTriggerEnter2D(Collider2D other){
if (other.tag == "Player") {
SceneManager.LoadScene("PlayVideo");
Instantiate (door, WhereToSpawn.position, Quaternion.identity);
Destroy (gameObject);
}
}
}
And i am getting this error:
NullReferenceException: Object reference not set to an instance of an object
spawnDoor.Start () (at Assets/Scripts/spawnDoor.cs:19)
I understand that the problem is in line 19 but it seems good to me.I can’t see any mistake.Please help me.