I've set up a SQLite database with Unity. Into this I would like to add the current CPU Utilisation. The SQLite scripts are in Javascript and the method for finding the CPU utilisation is in a C# script, I have tried changing the javascript to C# but I am not that skilled. Ive tried several methods, each giving me errors:


private var csScript : ClientValues;

function Awake()
csScript = this.GetComponent("ClientValues");

using this method gives me the error "The name 'ClientValues' does not denote a valid type ('not found')"

and if I use (http://answers.unity3d.com/questions/272122/can-i-pass-a-value-from-a-c-script-into-a-java-scr.html)

var curValue : int;
var gObject2 : GameObject;

function Update()
var cSharpScript = gObject2.GetComponent("Clientvalues");
curValue = cSharpScript.myValue;

I get the error: 'myValue' is not a member of 'UnityEngine.Component'

Is this something to do with me using Unity 5? What can I do to have the Javascript access the C# value?


You have to cast it to ClientValues type.

var cSharpScript = (ClientValues)gObject2.GetComponent("Clientvalues");


var cSharpScript = gObject2.GetComponent("Clientvalues") as ClientValues;

First one causes runtime error if cast fails and the second one returns null if it fails. Important difference. But both should do the trick.

  • \$\begingroup\$ Thanks for the reply! Whenever I try the first i get a ';' expected, Insert a semicolon at the end. Whenver I try the second I get a The name 'ClientValues' does not denote a valid type ('not found'). Where am I going wrong here? Does it matter where I place these statements, I have both at the top of the script. \$\endgroup\$
    – CH99
    May 13 '15 at 13:09
  • \$\begingroup\$ Apologies got it working now! For anyone else reading my problem was that my C# script with the required value wasnt in my plugins folder. Placing it in there sorted this. Ty Katu :) \$\endgroup\$
    – CH99
    May 13 '15 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.