problème : le save et le load fonctionnait avec un string en mémoire solution : créer un fichier save.txt dans les assets quand on sauvegarde, et lire de ce fichier quand on load.
49 lines
956 B
C#
49 lines
956 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Opponent : Entity
|
|
{
|
|
|
|
private Vector2 _movementVector = Vector2.zero;
|
|
private Rigidbody2D _rigidbody;
|
|
|
|
void Start()
|
|
{
|
|
_rigidbody = GetComponent<Rigidbody2D>();
|
|
}
|
|
|
|
void Update() {
|
|
|
|
_movementVector.x = -Time.deltaTime * Speed;
|
|
|
|
_movementVector.Normalize();
|
|
|
|
_rigidbody.velocity = _movementVector * Speed;
|
|
|
|
if(IsEnemyDetected) {
|
|
AttackEnemy();
|
|
}
|
|
|
|
}
|
|
|
|
void AttackEnemy() {
|
|
//Attack Cooldown
|
|
if(AttackSpeed < AttackSpeedWait)
|
|
{
|
|
Enemy.Hp-=AttackDamage;
|
|
Debug.Log("Ally Hp = " + Enemy.Hp);
|
|
|
|
//Kill if no hp
|
|
if(Enemy.Hp <= 0) {
|
|
Destroy(Enemy);
|
|
}
|
|
|
|
AttackSpeedWait = 0f;
|
|
}
|
|
|
|
AttackSpeedWait += Time.deltaTime;
|
|
}
|
|
|
|
}
|