Search Unity

what do you put inside a if statement to get it to check if the object is touching something

Discussion in '2D' started by exploding_toaster, Jul 2, 2020.

  1. exploding_toaster

    exploding_toaster

    Joined:
    Jun 5, 2020
    Posts:
    46
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class box : MonoBehaviour
    6. { public SpriteRenderer sr;
    7.      void Update()
    8.     {
    9.        if() this.sr.enabled = false;  
    10.     }
    11. }
    12.  
    so i want to make it so that if i touch something i go invisible by turning off and on the sprite renderer
    but i dont know what to put inside the if statement to get input if im touching something or not
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
  3. exploding_toaster

    exploding_toaster

    Joined:
    Jun 5, 2020
    Posts:
    46
    i put a ontriggerenter and im getting a error saying it des not exist in the context
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class box : MonoBehaviour
    6. { public SpriteRenderer sr;
    7.      void Update()
    8.     {
    9.         if (OnTriggerEnter) this.sr.enabled = false;
    10.     }
    11. }
    12.  
     
  4. exploding_toaster

    exploding_toaster

    Joined:
    Jun 5, 2020
    Posts:
    46
    do i need to make a variable?
     
  5. exploding_toaster

    exploding_toaster

    Joined:
    Jun 5, 2020
    Posts:
    46
    FIXED IT THANKS