public void Move(AnimationEvent myEvent) { if (myEvent.objectReferenceParameter is MoveAnimationInfo) { MoveAnimationInfo m = (MoveAnimationInfo)myEvent.objectReferenceParameter; { if (onMoveAnimationEvent != null) { onMoveAnimationEvent(m); } } } }
public void MoveAnimationEvent(MoveAnimationInfo info) { Vector3 moveAmount = info.moveAmount; if (moveAmount.x != 0) { moveAmount.x *= -transform.localScale.x; } transform.position += moveAmount; //This may look bad on the surface but this has actually been a blessing //The less we use the physics the higher change that rollback will be easier //This can easily be refactored to check the stage limits with a scriptable object - it's fine for now float frontDir = Mathf.Sign(transform.localScale.x); if (transform.position.x > 7) { //Check which side the character is collidSing on if (frontDir == 1) { HitWallBack(); } else if (frontDir == -1) { HitWallFront(); } } else if (transform.position.x < -7) { //Check which side the character is colliding on if (frontDir == 1) { HitWallFront(); } else if (frontDir == -1) { HitWallBack(); } } Vector3 pos = transform.position; pos.x = Mathf.Clamp(pos.x, -7, 7); transform.position = pos; }