Forum rules - please read before posting.

Calling a scritp via action list

edited May 2014 in Technical Q&A
Hey all :)

I basically have a c# script that let me rotate objects...I'd like to turn at the begin at the begin of the game this script off so the object stay in place and then awake the script trough action list when I turn one menu so I can examinate the object rotating it...how can I achieve this? ty

Comments

  • If you place the turning code in a function called, eg RotateRight, you can use the Object: Send Message Action to call the GameObject with the script attached.  Set the message as custom: "RotateRight", and it'll run the function.
  • Even if I want to turn on a component? is the same? for example I have a component in an object and it starts off...how can I turn on the component?
  • Disabled components can't be "reached" by sending messages to them.  It's not good practice to enable/disable components like that.  A simple modification of the script itself would mean you don't have to do that.  However, you could use another script (that's always enabled) that has functions to enable/disable the other component manually (e.g. GetComponent <MyOtherScript>().enabled = true; ) .  You could send messages to that script instead.
  • So chris, I did like this:

    I have a bottle...attached to the bottle two scripts; one called ENABLEDISABLE and one called ROTATEWITHMOUSE.

    the first script control the second one trough an integer called canRotate...if the integer is 0 the rotatewithmouse script is disabled...if the integer is 1 the rotatewithmouse script is enabled...

    all working trough the inspector window of unity

    but if I try to run the action trough send object message is not working...I did like this...maybe I'm doing something wrong...

    Action type Object : Send Message
    Object to affect: Bottle
    Message to send : custom
    Method name: canRotate
    Pass integer to method : cheked
    Integer to send: 1
    after running continue

    where am I doing wrong?



  • The "method name" is the name of the function, not the integer.  You need to write a function that changes the integer's value.

    In JS:

    function SetValue (_newValue : int)
    {
        canRotate = _newValue;
    }

    In C-sharp:

    void SetValue (int
     _newValue)
    {
      canRotate = _newValue;
    }

    Then set the Method name as "SetValue".
  • Worked!

    P.S.: I putted the void update between the void start and the void update...is the right place? :P
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.