As said I have not really a clue about the UnityScript specifics and potential special syntax traps
But you already get a hold of the Renderer in
cubeRenderer = GetComponent(Renderer);
so I suppose in general instead of trying to go through
transform.renderer
you further on rather would want to use that cubeRenderer
Just for testing I installed Unity 2018.1 where it actually automatically updates the API from the deprecated transform.renderer to transform.GetComponent.<Renderer>().
Even in older c# API - from around the time UnityScript also got deprecated - these direct properties existed but were already deprecated
Which would be indicating you are using an even older version!
Anyway, I copied your exact provided code and got all kind of other syntax errors - not specifically the one you mention.
Among these e.g. it should also not be
if (Input.GetMouseButtonDown); // also note weird placed ; here
but rather
if (Input.GetMouseButtonDown(0)) { ... }
fixing both, syntax and logic errors.
And then also there is a couple of misplaced { } in e.g.
function OnMouseOver() { {
causing some of your methods being local functions embedded within others
It's a bit unclear what exact behavior you are trying to achieve with the coloring but this e.g. works for me now after fixing all mentioned issues:
#pragma strict public var Cube : GameObject; var cubeRenderer : Renderer; function Start() { //Get renderer component of the cube. cubeRenderer = GetComponent(Renderer); } function OnMouseEnter() { cubeRenderer.material.color = Color.green; } function OnMouseExit() { cubeRenderer.material.color = Color.white; } function OnMouseDown() { cubeRenderer.material.color = Color.red; } function OnMouseUp() { cubeRenderer.material.color = Color.blue; }
In general as said UnityScript is dead! This was deprecated in 2018 and I strongly recommend you drop it and get into c# instead!
You still using UnityScript also implies you are using a way out of date Unity Version from 2017!
To be fair I'm not coming from a JavaScript background but IMHO c# only has advantages over UnityScript:
- supported by all decent IDEs
- better debugging
- broader API
- maintained Unity API
- maintained Unity Version in the first place!
- (mostly) applicable outside of Unity
- direct hook into asynchronous coding, native plugins, strictly typed
- etc
Materialto a var and then modify and write it back ..? But no clue tbh ^^ as said.. c# guy here and that thing was in deprecation ever since I got into Unity so I never went deep into it ;)Componenthad properties for most of the "standard" built-in components likerenderer,collider.. evencamera.. even though marked as deprecated they kept them around for a long time actually.. which was a bit annoying when you called your own fields (or e.g. loop variable)rendereras it was then hiding that built-in deprecated one and IDEs would cry about it ^^cubeRenderer = GetComponent(Renderer);.. so why not just use that reference you got already? And yeah the direct properties might only be available inMonoBehavior(or in your case simply your own Unityscript components) but not in the built-in ones that often only inherit fromComponent.. not sure