@@ -7,7 +7,9 @@ public class UnitManager : MonoBehaviour
77{
88 public GameObject selectionCircle ;
99 public GameObject fov ;
10+ public Renderer meshRenderer ;
1011 public AudioSource contextualSource ;
12+ public Animator animator ;
1113
1214 public int ownerMaterialSlotIndex = 0 ;
1315
@@ -26,9 +28,13 @@ public class UnitManager : MonoBehaviour
2628 private Material _levelUpVFXMaterial ;
2729 private Coroutine _levelUpVFXCoroutine = null ;
2830
31+ private Vector3 _meshSize ;
32+ public Vector3 MeshSize => _meshSize ;
33+
2934 private void Awake ( )
3035 {
3136 _canvas = GameObject . Find ( "Canvas" ) . transform ;
37+ _meshSize = meshRenderer . GetComponent < Renderer > ( ) . bounds . size / 2 ;
3238 }
3339
3440 private void OnMouseEnter ( )
@@ -68,9 +74,9 @@ public void EnableFOV(float size)
6874 public void SetOwnerMaterial ( int owner )
6975 {
7076 Color playerColor = GameManager . instance . gamePlayersParameters . players [ owner ] . color ;
71- Material [ ] materials = transform . Find ( "Mesh" ) . GetComponent < Renderer > ( ) . materials ;
77+ Material [ ] materials = meshRenderer . materials ;
7278 materials [ ownerMaterialSlotIndex ] . color = playerColor ;
73- transform . Find ( "Mesh" ) . GetComponent < Renderer > ( ) . materials = materials ;
79+ meshRenderer . materials = materials ;
7480 }
7581
7682 public void Attack ( Transform target )
@@ -170,7 +176,7 @@ private void _SelectUtil()
170176 UpdateHealthbar ( ) ;
171177 Healthbar h = healthbar . GetComponent < Healthbar > ( ) ;
172178 Rect boundingBox = Utils . GetBoundingBoxOnScreen (
173- transform . Find ( "Mesh" ) . GetComponent < Renderer > ( ) . bounds ,
179+ meshRenderer . bounds ,
174180 Camera . main
175181 ) ;
176182 h . Initialize ( transform , IsMovable ( ) , boundingBox . height * 0.5f ) ;
@@ -215,7 +221,7 @@ public void LevelUp()
215221
216222 // create visual effect (+ discard it after a few seconds)
217223 GameObject vfx = Instantiate ( Resources . Load ( "Prefabs/Units/LevelUpVFX" ) ) as GameObject ;
218- Vector3 meshScale = transform . Find ( "Mesh" ) . localScale ;
224+ Vector3 meshScale = meshRenderer . transform . localScale ;
219225 float s = Mathf . Max ( meshScale . x , meshScale . z ) ;
220226 Transform t = vfx . transform ;
221227 t . localScale = new Vector3 ( s , meshScale . y , s ) ;
@@ -236,4 +242,16 @@ private IEnumerator _UpdatingLevelUpVFX()
236242 }
237243 Destroy ( _levelUpVFX ) ;
238244 }
245+
246+ public void SetAnimatorBoolVariable ( string name , bool boolValue )
247+ {
248+ if ( animator == null ) return ;
249+ animator . SetBool ( name , boolValue ) ;
250+ }
251+
252+ public void SetAnimatorTriggerVariable ( string name )
253+ {
254+ if ( animator == null ) return ;
255+ animator . SetTrigger ( name ) ;
256+ }
239257}
0 commit comments