Search Unity

Question Another 2D Destroy Collision Script

Discussion in '2D' started by QuartzCZ, Jul 30, 2021.

  1. QuartzCZ

    QuartzCZ

    Joined:
    Jul 27, 2021
    Posts:
    8
    Another error. please help me
    upload_2021-7-30_9-50-45.png
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,481
    What do you expect the compiler to do with the word "Wood"?

    If you want it destroyed there then use the same that you did in the code further down.

    Note that this isn't a 2D thing, this is a basic scripting thing and should be posted here.

    Also, you already posted this, ignore my reply and posted it again. I would suggest you look up a few tutorials on using C# in Unity before you go much further. It'll save you a lot of pain.
     
  3. QuartzCZ

    QuartzCZ

    Joined:
    Jul 27, 2021
    Posts:
    8
    Thanks
     
  4. maross334

    maross334

    Joined:
    Jul 28, 2021
    Posts:
    9
    An easy fix would be to create a condition.

    Initialize a bool and assign it in the OnCollisionEnter function by checking what the local variable 'other' is equal to. If it's wood, bool = true. If it's not wood, bool = false. Use this bool as a condition for the if statement, on line 13, in conjunction with the button press.

    Just trying to practice my code speak :) Hope it helps... but seriously, listen to MelvMay...