41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Root : MonoBehaviour
|
|
{
|
|
|
|
[SerializeField]
|
|
private Entity _entity;
|
|
[SerializeField]
|
|
private GameObject _projectile;
|
|
[SerializeField]
|
|
private Transform _projectileSpawn;
|
|
|
|
void Attack() {
|
|
_entity.Enemy.Hit( _entity.AttackDamage);
|
|
if(_entity.Enemy.Hp <= 0) {
|
|
_entity.Enemy.Death();
|
|
_entity.IsEnemyDetected = false;
|
|
}
|
|
}
|
|
|
|
void ShotProjectile() {
|
|
Rigidbody2D _rigidbodyAlly;
|
|
Rigidbody2D _rigidbodyOpponent;
|
|
_rigidbodyAlly = _entity.GetComponent<Rigidbody2D>();
|
|
_rigidbodyOpponent = _entity.Enemy.GetComponent<Rigidbody2D>();
|
|
|
|
Vector3 spawnPos = (_projectileSpawn == null) ? _rigidbodyAlly.position : _projectileSpawn.position;
|
|
GameObject _newArrow = Instantiate(_projectile, spawnPos, Quaternion.identity);
|
|
|
|
//Warning : the Speed of the arrow is equal to the speed of this unit, if this unit need to move, use an other variable !
|
|
_newArrow.GetComponent<Projectile>().Damage = _entity.AttackDamage;
|
|
_newArrow.GetComponent<Projectile>().EnemySpeed = _entity.Enemy.Speed;
|
|
_newArrow.GetComponent<Projectile>().VectorStart = _rigidbodyAlly.position;
|
|
_newArrow.GetComponent<Projectile>().VectorEnd = _rigidbodyOpponent.position;
|
|
_newArrow.GetComponent<Projectile>().Target = _entity.Enemy;
|
|
|
|
}
|
|
}
|