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

Need Help :/

Discussion in 'Scripting' started by Hiktses, Jun 14, 2020.

  1. Hiktses

    Hiktses

    Joined:
    May 30, 2020
    Posts:
    19
    I am trying to make a Plane Shooter game.The part that i need help is enemy movement.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class EnemyMovement : MonoBehaviour
    4. {
    5.     public float speed;
    6.     public bool MoveRight;
    7.  
    8.  
    9.  
    10.  
    11.     void Update()
    12.     {
    13.  
    14.  
    15.         if (MoveRight)
    16.         {
    17.  
    18.             transform.Translate(2 * Time.deltaTime * speed, 0, 0);
    19.             transform.localScale = new Vector2(-6, 8);
    20.         }
    21.         else
    22.         {
    23.  
    24.             transform.Translate(-2 * Time.deltaTime * speed, 0, 0);
    25.             transform.localScale = new Vector2(6, 8);
    26.         }
    27.  
    28.        
    29.  
    30.     }
    31.  
    32.     void OnTriggerEnter2D(Collider2D trig)
    33.     {
    34.  
    35.  
    36.         if (trig.gameObject.CompareTag("Wall"))
    37.         {
    38.  
    39.             if (MoveRight)
    40.             {
    41.  
    42.                 MoveRight = false;
    43.  
    44.             }
    45.             else
    46.             {
    47.  
    48.                 MoveRight = true;
    49.  
    50.             }
    51.         }
    52.  
    53.  
    54.     }
    55.  
    56.  
    57.  
    58.  
    59.  
    60. }
    61.  

    Error is : "Tag : Wall is not defined"
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,151
    You're using CompareTag for "Wall" but you haven't defined Wall as a tag. When you click a gameObject and look at the inspector, the top has a tag drop down. You should have Wall there, and if not, you need to create it.
     
    Hiktses likes this.
  3. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    10,004
    Edit/Project Settings...
    answer.PNG

    And then select the game objects what you want to tag as "Wall" and tag here:
    answer1.PNG
     
    Brathnann and Hiktses like this.
  4. Hiktses

    Hiktses

    Joined:
    May 30, 2020
    Posts:
    19
    Yeah you are right.I made a layer instead of tag.Thank you for helping :)
     
  5. Hiktses

    Hiktses

    Joined:
    May 30, 2020
    Posts:
    19
    Sorry, I didn't saw yours.Thank you too.
     
    Lurking-Ninja likes this.