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(); _rigidbodyOpponent = _entity.Enemy.GetComponent(); 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().Damage = _entity.AttackDamage; _newArrow.GetComponent().EnemySpeed = _entity.Enemy.Speed; _newArrow.GetComponent().VectorStart = _rigidbodyAlly.position; _newArrow.GetComponent().VectorEnd = _rigidbodyOpponent.position; _newArrow.GetComponent().Target = _entity.Enemy; } }