Unity Community

Register or Sign In:

+ Reply to Thread
Results 1 to 5 of 5

  1. Location
    FRENCH DUDE IN CALIFORNIA
    Posts
    361

    switching ON/OFF a C# script with a javascript script during runtime.

    //Hi folks,

    if(is there anybody in who can explain me the way to enable or not a C# script while application is playing?)
    {
    answer me back ();
    } else {
    breackMyHeadAgainstTheWall ();
    }

    I'm not joking !!! Indeed, i really need to enable or not the leg animator scrpt according to the isgrounded() function from third person platformer script so that my character can jump or doubleJump without awfull artifacts.
    I only know a lilttle bit of javascript within unity because i'm a 3D artist ...

    Thanks in advance for your answers


  2. Location
    Toronto, Ontario, Canada
    Posts
    1,310
    I think you want to set its "enabled" property to false:
    someGameObject.enabled = false

    http://unity3d.com/support/documenta...=MonoBehaviour

    if (this happens to work)
    {
    praiseMyAwesomness();
    }
    else
    {
    reportLackOfSuccess();
    someoneElseWhoKnowsWhatThey'reTalkingAbootHelpsIns tead(tomvds, Jesse Anders, Eric5h5);
    }
    Last edited by FizixMan; 10-25-2010 at 11:23 AM.


  3. Location
    FRENCH DUDE IN CALIFORNIA
    Posts
    361
    Well, thanks for your fast reply... But there is a misunderstanding : my javascript and my C# script are on the same game object : My character has the locomotion system script on him and the third person platformer script for moving and triggering animations. My problem is that when i jump it happens weird ugly artifacts and jump animations don't play correctly ( and i know that's because of the leg animator C# script. So how can i ( within my third person platformer javascript) :


    var leganimator : legAnimator = GetComponent(legAnimator); // here i want to get the leg animator C# script ...
    function LateUpdate()
    {
    if(jumping())
    {
    leganimator.enabled = false;
    } else {
    leganimator.enabled = true;
    }
    }

    // when i do that i've got an error it can't find the component legAnimator
    // I browse the forum and i saw that the C# script must be in the standard asset folder so i moved it but i had the same error ...
    //Someone could help ?


  4. Posts
    445
    Accessing C# scripts in UnityScript and vice-versa is messy! Do you really need both languages for this?

    I'll assume yes. First, make sure you've put the files in the right places per this document:
    http://unity3d.com/support/documenta...dvanced29.html

    Next, try this code. It works with both scripts are components on the same object:

    C#:
    Code:  
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class FrameCounter : MonoBehaviour {
    5.    
    6.     public int frameCount = 0;
    7.    
    8.     // Update is called once per frame
    9.     void Update () {
    10.         if ( (++frameCount % 100) == 0) {
    11.             Debug.Log( "frameCounter = " + frameCount );
    12.         }
    13.     }
    14.    
    15. }

    UnityScript:

    Code:  
    1. function Update () {
    2.     if ( Input.GetKeyDown( KeyCode.S ) ) {
    3.        var fc : FrameCounter;
    4.        fc = gameObject.GetComponent("FrameCounter");
    5.        fc.enabled = false;
    6.     }
    7. }

    You will of course need to modify this code for your purposes, but it illustrates the general idea.


  5. Location
    FRENCH DUDE IN CALIFORNIA
    Posts
    361
    thanks for your reply ! i'll try to adapt your code to my purpose.
    regards