Search Unity

AI Enemy Collision Detection

Discussion in '2D' started by Napster_03, Apr 25, 2019.

  1. Napster_03

    Napster_03

    Joined:
    Mar 26, 2019
    Posts:
    7
    Im trying to code an ai enemy, but cant figure out how to include collision. I tried setting Character collision detection 2d as a boolean, but that raised a lot of error messages. Any ideas?
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Alien1 : MonoBehaviour
    6. {
    7.     public Vector2 moving = new Vector2();
    8.     // Start is called before the first frame update
    9.     void Start()
    10.     {
    11.  
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     void Update()
    16.     {
    17.  
    18.         public bool collisionDetection = CollisionDetectionMode2D
    19.  
    20.         moving.x = moving.y = 0;
    21.  
    22.         if (collisionDetection = false)
    23.         {
    24.             moving.x = 1;
    25.         }
    26.         else if (collisionDetection = true)
    27.         {
    28.             moving.x = -1;
    29.         }
    30.  
    31.     }
    32. }
    33.