Blog

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

unity
programming
tutorial
game-development
scripting

> make sure you've put the files in the right places per this document: > > > Next, try this code. It works with both scripts are components on the same...

November 11, 2010 • Brandon Wu

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:

using UnityEngine;
using System.Collections;

public class FrameCounter : MonoBehaviour {
	
	public int frameCount = 0;
	
	// Update is called once per frame
	void Update () {
		if ( (++frameCount % 100) == 0) {
			Debug.Log( "frameCounter = " + frameCount );
		}
	}
	
}

UnityScript:

Code:

function Update () {
	if ( Input.GetKeyDown( KeyCode.S ) ) {
	   var fc : FrameCounter;
	   fc = gameObject.GetComponent("FrameCounter");
       fc.enabled = false;
    }
}

via forum.unity3d.com

Posted via email from Next Level with Brandon