Using Sequences in C# Scripts

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
annathehank
Posts: 95
Joined: Sun May 03, 2020 2:17 pm

Using Sequences in C# Scripts

Post by annathehank »

Hello again! Today I'm trying to wrap my head around how to use the sequencer commands in a script. I'm creating a sort of loot box system, and am trying to implement the MoveTo() sequence to help.
In the script I'm using, I have an array for the different objects you can find in the boxes, and I want to use the command to move the image of the object to an empty game object on the canvas. I'm a little worried doing a simple transform on the object to a location may get messed up as the camera moves around in the game.

This is the script so far. I'd like to add a line in the Onbuttonpress void that moves the moniObject being called forward to an empty gameobject.

Code: Select all

 public Moni[] monis;

    [System.Serializable]
    public class Moni
    {
        public string moniName;
        public GameObject moniObject;
        public int rating;
    }

    public void Onbuttonpress()
    {
       
            int moniIndex = Random.Range(0, monis.Length);
            Debug.Log("you have invited " + monis[moniIndex].moniName);
            Debug.Log("They are a " + monis[moniIndex].moniObject);
        
    }
Thank you in advance! <3
User avatar
Tony Li
Posts: 21961
Joined: Thu Jul 18, 2013 1:27 pm

Re: Using Sequences in C# Scripts

Post by Tony Li »

Hi,

To play a sequence in C# code, use DialogueManager.PlaySequence():

Code: Select all

DialogueManager.PlaySequence("MoveTo(Empty Box, MoniABC, 2)");
Another option, outside of the Dialogue System, is to use a tweening library such as DOTween. It's a useful tool for changing things from one value to another, such as moving an object from one position to another.
annathehank
Posts: 95
Joined: Sun May 03, 2020 2:17 pm

Re: Using Sequences in C# Scripts

Post by annathehank »

Wow, it really was that simple, huh? :lol: I think I got myself thinking it was more complicated by looking at the reference guide and everything. Thank you!
User avatar
Tony Li
Posts: 21961
Joined: Thu Jul 18, 2013 1:27 pm

Re: Using Sequences in C# Scripts

Post by Tony Li »

Happy to help!
Post Reply