Royal
Royal

Reputation: 41

Cannot find instance of an object

The problem I am facing at the moment is that right now I have warnings: enter image description here

which are created by this code snippet: enter image description here

But if I correct the code by changing line 24 to: enter image description here

The result is an error saying that in line 24 the insance is not declared, in the picture is visible that I added the script to my GameObject, but it has no variables filled in. enter image description here

Been dealing with this for 2 days now, really need your help. Thank you!

Upvotes: 0

Views: 248

Answers (2)

Snickbrack
Snickbrack

Reputation: 976

try this: (dots in wrong position)

#pragma strict
var CatClickFinished : CatClickFinished;
var passToDisable;
var rendCat110 : Renderer;
var rendCat210 : Renderer;
var enablePrintedPage : enablePrintedPage;
var enableCats;
var increment : int = 0;
var CatFiltered110 : GameObject;
var CatFiltered210 : GameObject;

var enabledCat110210 : boolean = false;

function Start () {
    CatFiltered110 = GameObject.Find("CatFiltered1.10");
    rendCat110 = CatFiltered110.GetComponent<Renderer>();

    CatFiltered210 = GameObject.Find("CatFiltered2.10");
    rendCat210 = CatFiltered210.GetComponent<Renderer>();



}

function Update () {

    GameObject.Find("CatFiltered110").AddComponent<enablePrintedPage>();
    enableCats = enablePrintedPage.enableCats;

    GameObject.Find("CatFiltered110").AddComponent<CatClickFinished>();
    passToDisable = CatClickFinished.passToDisable;

    SymbolsEnabled();
    DisableSprite();
}

function OnMouseOver(){
    if(Input.GetMouseButton(0)){
        rendCat110.enabled = true;
        rendCat210.enabled = true;
        enabledCat110210 = true;
    }
}

    function SymbolsEnabled(){
        if(enableCats && increment == 0){
            var cat : BoxCollider = gameObject.AddComponent<BoxCollider>(); //enabled box colliders on cat symbols
            increment = 1;
        }
    }

    function DisableSprite(){
        if(passToDisable){
            Destroy(gameObject);
        }
    }

Upvotes: 0

Desutoroiya
Desutoroiya

Reputation: 544

Change all your code with GetCompenent and AddComponent into:

rendCat110 = CatFiltered110.GetComponent<Renderer>();

the . you have after GetComponent will give you an error.

Upvotes: 1

Related Questions