kot14217

How to correctly register the inclusion of a specific skeletal animation in OnCollisionEnter2D in unity?
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag.Equals("Wall"))
{
SetAnimation(Walljumping, true, 2f);???????????? does not work(((
}

}
private void OnCollisionExit2D(Collision2D collision)
{
if (collision.gameObject.tag.Equals("Wall"))
{
????
}
}


I want to make a jump from the wall. so that when you touch the wall, the animation works
kot14217
  • Mesajlar: 8

Luke

Hello,

Would you mind posting some more context about your issue, and your code?
Luke

Luke
  • Mesajlar: 105

kot14217

Luke yazdı:Hello,

Would you mind posting some more context about your issue, and your code?
just please tell me how to write a line to play Spine animation, in frame-by-frame animation it is Animator Play ("Walljumping"), and how to prescribe it for Spine animation???
kot14217
  • Mesajlar: 8

Harald

Please have a look at the spine-unity documentation pages:
spine-unity Runtime Documentation: Animation AnimationState
You can also have a look at the example scenes that are included in the spine-unity runtime unitypackage, you may want to start with the example scenes Spine Examples/Getting Started.
Kullanıcı avatarı
Harald

Harri
  • Mesajlar: 3905

kot14217

void Start()
{
rigidbody = GetComponent<Rigidbody2D>();
currentState = "Idle";
SetCharacterState(currentState);
}
private void FixedUpdate()
{
if (Physics2D.Linecast(transform.position, GroundCheck.position, 1 << LayerMask.NameToLayer("Ground")))
{
isGrounded = true;
}
else
{
isGrounded = false;
SetAnimation(jumping, false, 1f);
}
}
// Update is called once per frame
void Update()
{
Move();
if (isGrounded == true )
{
canJump = true;
}
else
{
canJump = false;
}
if (canWallJump == true)
{
canJump = true;
SetCharacterState("WallJUMP");
}
Dash();
}
public void SetAnimation(AnimationReferenceAsset animation, bool loop, float timeScale)
{
if (animation.name.Equals(currentAnimation))
{
return;
}
Spine.TrackEntry animationEntry = skeletonAnimation.state.SetAnimation(0, animation, loop);
animationEntry.TimeScale = timeScale;
animationEntry.Complete += animationEntry_Complete;
currentAnimation = animation.name;
}
private void animationEntry_Complete(Spine.TrackEntry trackEntry)
{
if (currentState.Equals("Jumping"))
{
SetCharacterState(previousState);
}
}
public void SetCharacterState(string state)
{
if (state.Equals("Run"))
{
SetAnimation(run, true, 2f);
}
else if (state.Equals("Jumping"))
{
SetAnimation(jumping, false, 2f);
}
else
{
SetAnimation(idle, true, 1f);
}
if (state.Equals("DASH"))
{
SetAnimation(DASH, true, 1f);
}
if (state.Equals("WallJUMP"))
{
{
SetAnimation(WallJUMP, false, 1f);
return;
}
}
currentState = state;
}
public void Move()
{
movement = Input.GetAxis("Horizontal");
rigidbody.velocity = new Vector2(movement * speed, rigidbody.velocity.y);
if (movement != 0)
{
if (!currentState.Equals("Jumping"))
{
SetCharacterState("Run");
}
if (movement > 0)
{
transform.localScale = new Vector2(0.1f, 0.1f);
}
else
{
transform.localScale = new Vector2(-0.1f, 0.1f);
}
}
else
{
if (!currentState.Equals("Jumping"))
{
SetCharacterState("Idle");
}
}
if (Input.GetButtonDown("Jump") && canJump)
{
Jump();
}
}
public void Jump()
{
rigidbody.velocity = new Vector2(rigidbody.velocity.x, jumpSpeed);
if (!currentState.Equals("Jumping"))
{
previousState = currentState;
}
SetCharacterState("Jumping");
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag.Equals("Wall"))
{
canWallJump = true;
}
}
private void OnCollisionExit2D(Collision2D collision)
{
if (collision.gameObject.tag.Equals("Wall"))
{
canWallJump = false;
}
}
void Dash()
{
if (Input.GetKeyDown(KeyCode.LeftControl) && !lockDash)
{
lockDash = true;
Invoke("DashLock", 1f);
SetCharacterState("DASH");
rigidbody.velocity = new Vector2(0, 0);

if (!currentState.Equals("Dash"))
{
previousState = currentState;
}
if (rigidbody.transform.localScale.x < 0)
{
rigidbody.AddForce(Vector2.left * DashInpulse);
}

else
{
rigidbody.AddForce(Vector2.right * DashInpulse);
}
}
}
private bool lockDash = false;
void DashLock()
{
lockDash = false;
}
}
WallJUMP and DASH animations only play the first frame.You can see where there are errors in the code for these two animations and what I need to fix.I can't figure it out by myself!please take a couple of minutes of your time and look at the code.
kot14217
  • Mesajlar: 8

Harald

Regarding formatting: please use the three backticks
```
before and after your pasted code, or use the code tags:
[code]
code goes here
[/code]
or the code button in the Full Editor to format your pasted code, otherwise your code indentation is messed up and unreadable.

Regarding your questions:
kot14217 yazdı:just please tell me how to write a line to play Spine animation, in frame-by-frame animation it is Animator Play ("Walljumping"), and how to prescribe it for Spine animation???
Your code shows the following line:
Spine.TrackEntry animationEntry = skeletonAnimation.state.SetAnimation(0, animation, loop);
This plays a Spine animation already. I'm afraid I don't understand your question correctly. Could you please describe im more detail what you want to achieve, and what problems you are facing?
Kullanıcı avatarı
Harald

Harri
  • Mesajlar: 3905


Dön Unity