using GatherAndDefend; 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; public void Attack() { if (_entity == null || _entity.Enemy == null) return; _entity.Enemy.Hit(_entity.AttackDamage); if(_entity.Enemy.Hp <= 0) { _entity.Enemy.Death(); _entity.IsEnemyDetected = false; } } public void ShotProjectile() { Rigidbody2D _rigidbodyAlly; Rigidbody2D _rigidbodyOpponent; _rigidbodyAlly = _entity.GetComponent(); if (!_entity.Enemy) return; _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().Origin = _entity; } public void PlaySound(string soundName) { _entity.PlaySound(soundName); } }