73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PoliceBombBehavioru : MonoBehaviour
|
|
{
|
|
public GameObject bomb;
|
|
public int bombsAmount;
|
|
public int policecarVerticalSpeed;
|
|
public int policecarHorizontalSpeed;
|
|
public float bombDelay;
|
|
[HideInInspector]
|
|
public int pointsPerCar;
|
|
|
|
private float Delay;
|
|
private GameObject playerCar;
|
|
private Vector3 policecarpos;
|
|
|
|
void Start()
|
|
{
|
|
playerCar = GameObject.FindWithTag("Player");
|
|
Delay = bombDelay;
|
|
}
|
|
|
|
void FixedUpdate()
|
|
{
|
|
if (playerCar == null)
|
|
{
|
|
playerCar = GameObject.FindWithTag("Player");
|
|
}
|
|
else
|
|
{
|
|
policecarpos = Vector3.Lerp(transform.position, playerCar.transform.position, Time.deltaTime * policecarHorizontalSpeed);
|
|
Mathf.Clamp(policecarpos.x, -2.4f, 2.4f);
|
|
transform.position = new Vector3(policecarpos.x, transform.position.y, 0);
|
|
}
|
|
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
|
|
if(gameObject.transform.position.y > 3.8f && bombsAmount > 0)
|
|
{
|
|
this.gameObject.transform.Translate(new Vector3(0, -1, 0) * policecarVerticalSpeed * Time.deltaTime);
|
|
|
|
} else if (bombsAmount <= 0)
|
|
{
|
|
this.gameObject.transform.Translate(new Vector3(0, 1, 0) * policecarVerticalSpeed * Time.deltaTime);
|
|
if(gameObject.transform.position.y > 6.5f)
|
|
{
|
|
PointsManager.points += pointsPerCar;
|
|
Destroy(this.gameObject);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Delay -= Time.deltaTime;
|
|
if(Delay <=0 && bombsAmount > 5)
|
|
{
|
|
Delay = bombDelay;
|
|
bombsAmount--;
|
|
Instantiate(bomb, transform.position, Quaternion.identity);
|
|
} else if (Delay <= 0 && bombsAmount <=5 && bombsAmount > 0)
|
|
{
|
|
Delay = bombDelay / 2;
|
|
bombsAmount--;
|
|
Instantiate(bomb, transform.position, Quaternion.identity);
|
|
}
|
|
}
|
|
}
|
|
}
|