Fairly new to Unity development and i do apologise if its a quick simple answer. So basically i have a player object that does not move or collide with anything and stays at the top of the screen, however objects (enemies) spawn from both left and right sides of the screen and you have to tap to destroy them before they collide with each other, otherwise the player will lose health. I have a animator set up with 5 different states that each have a single sprite each to signify the health of the player ( eg. full health, half health, dead). I am having trouble trying to figure out how to go about scripting so when the two enemies collide, then the player will lose health and change to the next state / sprite. As im using the script that is connected to the enemy objects and the animator component is connected to the player object how would i also go about referencing the animator component from another game objects script?
You need to setup some variables in the animator which define a state change, then in your C# code:
Animator animator = GetComponent<Animator>(); animator.Set[Int|Float|Bool|etc...]("variable name", variable value); // This means for each primitve data type there's a setter.