I have a enemy code that changes direction it moves every couple seconds but the bool that says wich direction to go is not changing
here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy3Script : MonoBehaviour {
//Movement
public float Speed = 1f;
public float Movetime = 2f;
public float _movetime;
public bool MovingLeft;
//Shooting
public float ShootSpeed = 2f;
private float _ShootSpeed;
public GameObject Bullet;
void Start()
{
}
void Update()
{
//Move Left And Right
// Here is the problem \/ \/ \/ \/
if (MovingLeft = true)
{
_movetime = _movetime - Time.deltaTime;
var Pos = transform.position;
Pos.x = Pos.x - Time.deltaTime * Speed;
transform.position = Pos;
if (_movetime <= 0)
{
_movetime = Movetime;
MovingLeft = false;
}
}else
{
_movetime = _movetime - Time.deltaTime;
var Pos = transform.position;
Pos.x = Pos.x + Time.deltaTime * Speed;
transform.position = Pos;
if (_movetime <= 0)
{
_movetime = Movetime;
MovingLeft = true;
}
}
//Shoot
_ShootSpeed = _ShootSpeed - Time.deltaTime;
if (_ShootSpeed <= 0)
{
_ShootSpeed = ShootSpeed;
Instantiate(Bullet, transform.position, transform.rotation);
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log("Hit");
//If Hit Bullet Destroy Self
if (collision.gameObject.name == "Bullet(Clone)")
{
Debug.Log("Dead");
ScoreScript.Score = ScoreScript.Score + 50f;
Time.timeScale = Time.timeScale + 0.015f;
Destroy(gameObject);
}
}
}