Image
Top
Menu
November 10, 2010

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

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;
    }
}




Posted via email from Next Level with Brandon


Posted By

Categories

Blog Posts, Unity3D

Tags