I try making a box, which I touch with the character (fps controller), it loads the next level.
I add a script to the box (not to the controller, with the controller and OnControllerCillisionEnter it works):
using UnityEngine;
using System.Collections;
public class OnHit : MonoBehaviour
{
void OnCollisionEnter (Collision cInfo)
{
Application.LoadLevel("TestScene");
}
}
What’s the problem with this?
Nothing, but do you have a collider component attached to the same object with "Is Trigger" checked, and also a rigidbody with "Is Kinematic" checked? EDIT: Right, also changing the "OnCollisionEnter" to "OnTriggerEnter". Good job figuring that out.
Yes, I have a rigidbody on the FPS controller, and box collider on the box. I tried switching between isTrigger, isKinetic and change the OnCollisionEnter(Collision c) to OnTriggerEnter(Collider c) but don't work for me. Somebody explain me, cause I haven't got more ideas.
Are you sure that TestScene is what your other scene is called? And I don't know whether this is necessary, but if your sure you named it correctly - have you added it to the scenes included in your game (under File>Build Settings)? Maybe just try doing something else instead of loading a new level, for example just try: Debug.Log("This code is being executed properly");
On the box (cube) is a box collider, with isTrigger and I attached the script.
I add rigidbody to the controller.
The Script:
using UnityEngine;
using System.Collections;
public class OnHit : MonoBehaviour
{
void OnTriggerEnter (Collider cInfo)
{
Debug.Log("Hit the Cube");
if(cInfo.gameObject.name == "First Person Controller")
{
Application.LoadLevel("TestScene1");
}
}
}
Nothing, but do you have a collider component attached to the same object with "Is Trigger" checked, and also a rigidbody with "Is Kinematic" checked? EDIT: Right, also changing the "OnCollisionEnter" to "OnTriggerEnter". Good job figuring that out.
– blitzenWhat @blitzen said, make sure one of your objects (preferably your player) has a rigidbody on it, else the collisions will not be detected.
– tonycoculuzziYes, I have a rigidbody on the FPS controller, and box collider on the box. I tried switching between isTrigger, isKinetic and change the OnCollisionEnter(Collision c) to OnTriggerEnter(Collider c) but don't work for me. Somebody explain me, cause I haven't got more ideas.
– ZyklonAre you sure that TestScene is what your other scene is called? And I don't know whether this is necessary, but if your sure you named it correctly - have you added it to the scenes included in your game (under File>Build Settings)? Maybe just try doing something else instead of loading a new level, for example just try: Debug.Log("This code is being executed properly");
– ByteSheep