Search Unity

HELP bug about collision detection

Discussion in 'Getting Started' started by Avocadostudio1, Mar 23, 2023.

  1. Avocadostudio1

    Avocadostudio1

    Joined:
    Nov 21, 2022
    Posts:
    8
    the error says IDENTIFIER EXPECTED in my code about collision detection
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class NextLevel : MonoBehaviour
    6. {
    7.  
    8.     public GameObject BIRD;
    9.  
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.        
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.         void OnTriggerEnter (BIRD.gameobject.tag = "Projectile")
    20.         {
    21.             //some code i havent written yet
    22.         }
    23.     }
    24. }
    25.  
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,939
    There's a lot of invalid syntax there. Not sure what tutorial you're following, but you'll want to take a closer look. Always refer to the docs first too: https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html

    Such as:
    Code (CSharp):
    1. private void Update()
    2. {
    3.    
    4. }
    5.  
    6. private void OnTriggerEnter(Collider other)
    7. {
    8.     if (other.CompareTag("Projectile"))
    9.     {
    10.        
    11.     }
    12. }
     
  3. Avocadostudio1

    Avocadostudio1

    Joined:
    Nov 21, 2022
    Posts:
    8
    Do i leave the other there with the tag thing
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,939
    Read the docs. It tells you what is required of OnTriggerEnter.
     
  5. Avocadostudio1

    Avocadostudio1

    Joined:
    Nov 21, 2022
    Posts:
    8
    what does compare tags mean im trying to get the best understanding of this
     
  6. Avocadostudio1

    Avocadostudio1

    Joined:
    Nov 21, 2022
    Posts:
    8
    nevermind found it on the doc thanks never knew of this