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

Parser error in death code

Discussion in '2D' started by gpollak450, Jun 22, 2015.

  1. gpollak450

    gpollak450

    Joined:
    Jun 14, 2015
    Posts:
    7
    Hi im working on a death code and theres a parser error with void in line 14 heres my code:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Death : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.    
    9.     }
    10.    
    11.     // Update is called once per frame
    12.     void Update () {
    13.    
    14.         void OnTriggerEnter2D(Collider2D other) {
    15.             if(other.tag = "Player")
    16.             {
    17.            
    18.             {
    19.                 // Player entered red zone, reload game.
    20.                 Application.LoadLevel(0);
    21.             }
    22.         }
    23.     }
    Thanks in advance!
     
  2. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    You cannot put a method inside another method. (Here "OnTriggerEnter2D()" is inside "Update()".)
     
  3. gpollak450

    gpollak450

    Joined:
    Jun 14, 2015
    Posts:
    7
    Oh i see.
     
  4. gpollak450

    gpollak450

    Joined:
    Jun 14, 2015
    Posts:
    7
    now it just says parsing error ill try to figure this out by myself
     
  5. gpollak450

    gpollak450

    Joined:
    Jun 14, 2015
    Posts:
    7
    Im trying to figure this one out but im gonna need more help its says parsing error
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Example : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.    
    9.     }
    10.        
    11.         void OnTriggerEnter2D(Collider2D other) {
    12.             if(other.tag = "Player")
    13.             {
    14.                
    15.                 {
    16.                     // Player entered red zone, reload game.
    17.                     Application.LoadLevel(0);
    18.                 }
    19.             }
     
  6. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    Hint: Always keep the placement of braces and indentation of lines consistent.
     
  7. gpollak450

    gpollak450

    Joined:
    Jun 14, 2015
    Posts:
    7
    real awnser please
     
  8. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    Like I've said: Correct your indentation and braces, and you may spot and extra or missing one.
     
  9. JoakimCarlsson

    JoakimCarlsson

    Joined:
    Aug 27, 2014
    Posts:
    65
    Should look like this:
    Code (csharp):
    1.  
    2. public class Example : MonoBehaviour
    3. {
    4.  
    5.     // Use this for initialization
    6.     void Start()
    7.     {
    8.  
    9.     }
    10.  
    11.     private void OnTriggerEnter2D(Collider2D other)
    12.     {
    13.         if (other.tag == "Player")
    14.         {
    15.  
    16.             {
    17.                 // Player entered red zone, reload game.
    18.                 MediaTypeNames.Application.LoadLevel(0);
    19.             }
    20.         }
    21.     }
    22. }
    23.  
     
  10. trialforce

    trialforce

    Joined:
    Apr 15, 2012
    Posts:
    22