I am looking for some help on how to make a simple action happen. I have been going through some tutorials on youtube based on 2D gameplay in unity. I have learn quite a bit, but I find the scripting kinda random at how the game should be made.
In the tutorial, James makes a script for animating the player sprite, ie idle and running. Through that script I would like to add a hurt animation when the enemy collides with the player. In my attempts, I some how made the enemy die and the player to keep on playing. In the player sprite the rowNumber = 3; is for the hurt animation. Animations are 4 frames per row.
Now for my question, How, using the two scripts below, make the animations work? Think megaman when hit.
PlayerAnimate Script
#pragma strict
function Start ()
{
}
function FixedUpdate ()
{
var AT = gameObject.GetComponent(AnimateTexture);
if(Input.GetKey("a"))
{
AT.rowNumber = 1;
}
else if(Input.GetKey("d"))
{
AT.rowNumber = 1;
}
else
{
AT.rowNumber = 0;
}
}
Enemy Script
#pragma strict
private var fall : boolean;
var Player : GameObject;
var spawnPoint : Transform;
var stomp : boolean;
function Update () {
if(stomp){
transform.position.z = 4;
transform.localScale.y /= 2;
fall = true;
gameObject.GetComponent(PlatformMover).step = 0.0;
stomp = false;
}
if(fall){
transform.position.y -=0.1;
}
if(transform.position.y < -10){
Destroy(gameObject);
}
}
function OnTriggerEnter(other : Collider) {
if(!stomp){
}if(other.tag == "Player"){
Destroy(other.gameObject);
var P : GameObject = Instantiate(Player, spawnPoint.position, Quaternion.identity);
var sf = Camera.main.GetComponent(SmoothFollow2);
sf.target = P.transform;
}
}
My plan is to add a player health system instead of the current Destroy line. Thanks.