Open door = load scene c# issues

Ok so I’m attempting to teach myself this as I go but its so complicating!! :stuck_out_tongue: I’ve been trying to fix up this script by watching tutorials, forums, the unity manual, and nothing is helping! :frowning: I can’t seem to understand what the problem is, so I hope someone helps me out and doesn’t decide to freeze this question too, as I’ve been searching for days now. I don’t want an animation to play or anything. I just have a box collider set up in front of the door and I plan on having a line that pops up as you enter, saying “press ‘button’ to enter”. Then I’ll have a load screen and so on and so forth. But my main goal is to just proceed to the next scene, which would be the inside of the house. I get this error every time I try to use the script:

Assets/scripts/Scene_Prctice.cs(9,30): error CS0120: An object reference is required to access non-static member UnityEngine.Collision.gameObject'

using UnityEngine;
using System.Collections;

public class Scene_Prctice : MonoBehaviour 
{
	public void OnTriggerEnter (Collision collision)
	{
		if(Collision.gameObject.CompareTag == ("Player"))
		   {
			Application.LoadLevel ("noWhere");
		}
	}
}

Collision.gameObject is wrong. Thats a reference to a static method on the class Collision (which doesn’t exist)

What you want is collision.gameObject, thats a reference to a method on the instance passed in.

if(Collision.gameObject.transform.name == (“name of the Triger near door”))
{
Application.LoadLevel (“noWhere”);
}

remember u need to add the scene in build settings… only then
" Application.LoadLevel (“noWhere”); " function will work

Try this,

using UnityEngine;
using System.Collections;

public class Scene_Prctice : MonoBehaviour 
{
	public void OnTriggerEnter (Collider collision)
	{
		if(collision.gameObject.tag == "Player")
		{
			Application.LoadLevel ("noWhere");
		}
	}
}

about Trigger Go Unity - Scripting API: MonoBehaviour.OnTriggerEnter(Collider)

-Prasanna

Updated answer with SceneManager.

using System.Collections;
using UnityEngine.SceneManagement;
using System.Collections.Generic;
using UnityEngine;

public class LoadCOl : MonoBehaviour {

	void OnTriggerEnter (Collider other)
	{
		if(other.gameObject.CompareTag("Player"))
		{
			SceneManager.LoadScene(1);
		}
		
	}
}