-1

I am making a little game in c# on unity 5, and until now I have almost everything. How do I jump to another scene on detecting a rigidbody?

ryanyuyu
  • 6,366
  • 10
  • 48
  • 53
Fran910
  • 35
  • 5
  • When asking a question about a problem caused by your code, you will get much better answers if you provide code people can use to reproduce the problem. That code should be [a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – JasonWilczak Jun 17 '15 at 18:33
  • Welcome to Stack overflow. Please go through [how to ask](http://stackoverflow.com/help/how-to-ask). – Kushal Sharma Jun 17 '15 at 18:35
  • I just don't have any code it's just that. Our friend Adrew just help me out, but an parsen error come out saying that the void can't be after a public in this case... – Fran910 Jun 17 '15 at 18:59

1 Answers1

0

in one of your game object's scripts, put:

public void OnCollisionEnter(Collision col)
{
    Application.LoadLevel(nextLevel);
}

so implementation would look as such:

using UnityEngine;
using System.Collections;
public class BotonIrAInstrucciones : MonoBehaviour
{

    // Use this for initialization
    void Start () { }
    // Update is called once per frame
    void Update () { }

    public void OnCollisionEnter(Collision col)
    {
        Application.LoadLevel("Next Level");
    }
}
maraaaaaaaa
  • 7,749
  • 2
  • 22
  • 37
  • Where do i put that? In wich part of this? `using UnityEngine; using System.Collections; public class BotonIrAInstrucciones : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { }` – Fran910 Jun 17 '15 at 18:48
  • put it into the class of the object that will either hit something or get hit by something. – maraaaaaaaa Jun 17 '15 at 18:53
  • i said you put it inside of the class, so you have `public class BotonIrAInstrucciones : MonoBehaviour` and you make sure its between the `{` and `}` from that class level. you do not put it inside of any methods in that class and you don't put it outside of a class. – maraaaaaaaa Jun 17 '15 at 19:19
  • send me the entire text as you would do it, it keep throwing errors – Fran910 Jun 17 '15 at 19:26
  • Now don't have errors just don't want to work. It's like if can not be detected – Fran910 Jun 17 '15 at 19:34
  • BotonIrAInstrucciones game object needs a rigidbody component and both objects need to have colliders – maraaaaaaaa Jun 17 '15 at 19:37
  • i have it like that, but i dunno – Fran910 Jun 17 '15 at 19:41
  • Are you putting your scene's name instead of Next Level? – maraaaaaaaa Jun 17 '15 at 19:41
  • Your colliders aren't set to triggers? – maraaaaaaaa Jun 17 '15 at 19:45
  • Yes, but anyways onlything i do setting them as trigger is that my character sink into the floor – Fran910 Jun 17 '15 at 19:48
  • Yes but oncollisionenter also wouldn't execute if one was a trigger. Anyways, you aren't moving your character with transform directly right? You must be using rigidbody addforce or velocity. Also put `Debug.Log("asdf");` above the loadlevel command and tell me if it prints. – maraaaaaaaa Jun 17 '15 at 19:49
  • Can you edit it and send it to me? What do i put between the ´(" and ")´ – Fran910 Jun 17 '15 at 19:54
  • Edited. No need to change it, just let me know if "asdf" gets printed to your console upon a collision. – maraaaaaaaa Jun 17 '15 at 19:58
  • 1
    You did it my friend :D the error was that i couldn't read that the 2nd scene wasn't added to the build settings 'cause there were 2 audio listeners. THANK YOU – Fran910 Jun 17 '15 at 20:04
  • Okay good, so delete the debug part otherwise it will slow your game. – maraaaaaaaa Jun 17 '15 at 20:14