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

Question Please help Im new to C#

Discussion in 'Scripting' started by DashingMortis, Jun 3, 2020.

  1. DashingMortis

    DashingMortis

    Joined:
    Jun 1, 2020
    Posts:
    13
    Hi Im new to C# script coding so im stuck with this error: error CS0120: An object reference is required to access non-static member
    `UnityEngine.Collision.collider'
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Destroyer : MonoBehaviour {
    6.  
    7.     string strTag;
    8.  
    9.     void OnTriggerEnter2D(Collider2D other){
    10.        
    11.         if (Collision.collider.tag == strTag) {
    12.            
    13.         } else {
    14.             Destroy(other.gameObject);
    15.         }
    16.  
    17.        
    18.     }
    19. }
    20.  
    Thank btw
     
  2. Yanne065

    Yanne065

    Joined:
    Feb 24, 2018
    Posts:
    175
  3. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    Code (CSharp):
    1. if (Collision.collider.tag == strTag)
    should be
    Code (CSharp):
    1. if (other.gameobject.tag == strTag)
     
  4. DashingMortis

    DashingMortis

    Joined:
    Jun 1, 2020
    Posts:
    13
    Thanks bro