Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Help

Discussion in 'Getting Started' started by cookiegod19, Mar 3, 2024.

Thread Status:
Not open for further replies.
  1. cookiegod19

    cookiegod19

    Joined:
    Mar 2, 2024
    Posts:
    6
    Now it says Enemy.CanBeHarmed is not used what is going on here and how do I fix it.

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class Enemy : MonoBehaviour
    7. {
    8.     [SerializeField] float EnemyHp = 100f;
    9.  
    10.     [SerializeField] bool CanEnemyBeHarmed;
    11.  
    12.     public void Harm(float HarmHp)
    13.     {
    14.         if(CanEnemyBeHarmed = true);
    15.      {
    16.         if(EnemyHp > 0)
    17.         {
    18.             EnemyHp = EnemyHp - HarmHp;
    19.         }
    20.      
    21.      }
    22.     }
    23.  
    24.     void Update()
    25.     {
    26.       if(0 >= EnemyHp);
    27.       {
    28.        GetComponent(MeshRenderer).enabled = false;
    29.       }
    30.     }
    31. }
    32.  
    33.  
    34. }
     
    Last edited: Mar 3, 2024
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,933
    Do you have your console window open or a configured IDE? This code has lots of compile errors in it, you need to fix all of those before you can attach it to anything.
     
    cookiegod19 likes this.
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    This isn't much different from your previous post here. Please edit your posts to use code-tags rather than using plain text.

    I'll also move this post to the Getting Started forum for you which is a much more appropriate forum! :)

    Thanks.
     
    cookiegod19 and bugfinders like this.
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    Please use a single thread for a problem. Closing this as you've now made a duplicate here.
     
Thread Status:
Not open for further replies.