Search Unity

help needed on and off switch for invis

Discussion in '2D' started by exploding_toaster, Jul 3, 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 MeshRenderer sr;
    7.     private void OnTriggerEnter2D(Collider2D collision)
    8.     {
    9.         if (collision.transform.gameObject.name == "Diamond") { sr.enabled = false; }
    10.         if (collision.transform.gameObject.name == "Diamond" && sr.enabled = false) { sr.enabled = true; }
    11.     }
    12.  
    13.  
    14. }
    15.  
    im trying to make a on and off invis switch but its giving me this error

    CS0131 C# The left-hand side of an assignment must be a variable, property or indexer

    and i dont know what it means or how to fix it
     
  2. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    Line 10, single equal sign in "&& sr.enabled = false" causes the error, should be "=="
    Easier to just say !sr.enabled than checking if it's equal to false.
     
  3. exploding_toaster

    exploding_toaster

    Joined:
    Jun 5, 2020
    Posts:
    46
    thanks hopes it works