Search code examples
androidunity-game-engineunityscriptunity-web-player

Unity WebPlayer to Android Build Issues


I am new to Unity so a well stepped out answer would be nice. I am trying to make a dice roller on an Android platform. I was following this very well put together tutorial http://games.ucla.edu/resource/unity-1-beginner-tutorial-dice-making-pt-1/ (There is a second part too)

The problem is that it was made for a Web Player. If I try to build it for Android I get two particular errors.

I have two simple scripts with one error associated with each one.

SideTrigger.js - Error: BCE0019: 'currentValue' is not a member of 'UnityEngine.Component'.

public var faceValue = 0;
function OnTriggerEnter( other : Collider ) {
    var dieGameObject = GameObject.Find("SixSidedDie");

    var dieValueComponent = dieGameObject.GetComponent("DieValue");
    dieValueComponent.currentValue = faceValue; //ERROR HERE
    Debug.Log("Die1: " + faceValue);
}

DieValue.js - Error: BCE0019: 'text' is not a member of 'UnityEngine.Component'.

public var currentValue = 0;

function Update () {
    var dieTextGameObject = GameObject.Find("DieText");
    var textMeshComponent = dieTextGameObject.GetComponent("TextMesh");
    textMeshComponent.text = currentValue.ToString(); //ERROR HERE
}

I'm assume it's purely a syntactical issue, but I can't seem to find a solution.


Solution

  • GetComponent using string is not recommended due to performance reasons, it is documented here.

    It is better to use this:

    var dieValueComponent : DieValue = dieGameObject.GetComponent(DieValue)
    

    Or this:

    var dieValueComponent : DieValue = dieGameObject.GetComponent.<DieValue>()
    

    See if that works.