Forum rules - please read before posting.

Can anyone help me write a specific custom action?

Hi

This is a pretty specific issue - I'm using Anima2D to animate my characters, and using this tutorial (https://www.youtube.com/watch?v=09To3ZCIZUY&t=1s) I'm able to change the skin/ costume for the characters.

The issue is, the method described in the tutorial allows you to change the skin by jumping on a collider. I have been doing it until now, but now I need it to be done through an action list. For this reason, creating a custom action that changes the skin would be required. I should also mention that I do not know how to code at all.

On this page, the creator of the tutorial has described the functions/ variables his asset uses in order to change the skin.
Here is the code used in the collider that allows you to change skin by walking on the collider:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class skinchange : MonoBehaviour {

    public string skinToLoad = "chris_skin1";

    private void OnCollisionEnter2D(Collision2D collision)
    {
        SkinManager sm = collision.gameObject.GetComponent<SkinManager>();

        if (sm == null || string.IsNullOrEmpty(skinToLoad)) return;

        sm.LoadSkinByString(skinToLoad);
    }
}


Here, "chris_skin1" is the skin I want to change to. How could this be done through an action list rather than by using a collider? I have of course read the tutorial on how to create custom actions, but I don't know what to write in it for this case as I don't have coding knowledge.

I realize helping me with this might be a big time investment as you might have to spend time understanding Anima2D as well, but I'm not sure where else to ask for help for specifically creating an AC custom action. Sorry if this is not the right place to ask the question! I would, of course, be happy to mention your name(s) in the credits for guiding me through this process. :)

Thank you! 

Comments

  • If you don't care about being able to set the skin dynamically as you would in a typical Action's UI, there shouldn't actually be a need for a custom Action at all.  Custom Actions are generally only necessary if you want further controls.

    Here's a modified snippet of the code above, which moves it all into a single function with no parameters:


    If you add this to a GameObject, you'll then be able to fill in the "Skin Manager" field.  To make the skin change at runtime, call the ChangeSkin method.

    This can be called in an ActionList via either the Object: Send message or Object: Call event Actions.  If the new script is attached to your Player, and he's spawned at runtime, then use the former - check Send to Player?, set the Message to send as Custom, and the Method name to ChangeSkin.
  • Incredible!! It works :) Thank you so much @ChrisIceBox as always! I was able to make multiple skin changes also happen by attaching copies of the script to the player and changing the skin names in the code, and renaming method names to ChangeSkin2 etc.

    This makes things so much better! Now I don't need to force the character to walk on skin change buttons anymore lol. Thanks!! :smile:
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.