Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Why is this C# script is not working in Unity5?

Discussion in 'Scripting' started by NoobieNoob, Apr 11, 2015.

  1. NoobieNoob

    NoobieNoob

    Joined:
    Feb 18, 2015
    Posts:
    26
    I was following a youtube tutorial about creating a load scene script, I followed the tutorials exactly as it is and everything went as it should be in the tutorial but it is not working for me.
    Here is the script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class WinPoint : MonoBehaviour {
    5.     public string nextLevel;
    6.  
    7.     void Start () {
    8.  
    9.     }
    10.  
    11.     void Update () {
    12.  
    13.     }
    14.  
    15.     void OnTriggerEnter(Collider Others)
    16.     {
    17.         if (Others.tag == "W inPoint")
    18.         {
    19.             Application.LoadLevel(nextLevel);
    20.         }
    21.     }
    22. }
    23.  
    I attached it to the player and I added the tag WinPoint to the cube object that when I hit unity should load the next level (The cube object is triggered enabled too). Why the script is not working?
     
    Last edited: Apr 11, 2015
  2. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,804
    you have a space in the tag name comparison? "W inPoint" but if thats not the problem what does the following say:

    Code (CSharp):
    1.     void OnTriggerEnter(Collider Others)
    2.     {
    3.         Debug.Loig("tag: " + Others.tag);
    4.     }
     
  3. NoobieNoob

    NoobieNoob

    Joined:
    Feb 18, 2015
    Posts:
    26
    Oh that is right, my bad. It is working now
    Thanks a lot.