- Home /
An instance required.
this is the error . Assets/b2.js(27,18): BCE0020: An instance of type 'MyScriptName' is required to access non static member 'vuforiaVisible'.
how can i fix it.
var myObject : GameObject;
var yourScriptInstance : MyScriptName;
function Start(){
myObject = GameObject.Find("teapot");
yourScriptInstance=myObject.GetComponent(MyScriptName);
//MyScriptName is your script with var enabledState:bool=true;var vuforiaVisible:bool=false;
}
function Update () {
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){
if (guiTexture.HitTest(Input.GetTouch(0).position)){
if (MyScriptName.vuforiaVisible)
{
myObject.renderer.enabled = myScript.enabledState!=myScript.enabledState;
}
}
}
}
Answer by sirival · Nov 15, 2012 at 09:42 PM
Change this line:
if (MyScriptName.vuforiaVisible)
to:
if (yourScriptInstance.vuforiaVisible)
hey thats my answer, I got it first! :P
though admittedly i wrote a short explanation. yours is just the short answer.
sorry maybe repost a new question. I don't do mobile and don't know image tracking. I mean you have a vuforia visible but presumably the bool vuforiavisible is true even when the object leaves the screen. the vuforiavisible code would need to be seen but it would need to be seen by someone who know how to manipulate vuforia images. :P
I'm sorry about the duplicate answer I actually posted before you posted yours but due to my low karma the answer had to be approved by a moderator...
Answer by sparkzbarca · Nov 15, 2012 at 09:31 PM
oh my bad you did it right. I was speaking of C# your using UnityScript.
Basically what the error says is that this line here
if(MyScriptName.vuforiaVisible)
doesn't make sense because MyScriptName is a class not a variable
what you actually want is
if(yourScriptInstance.vuforiaVisible)
yourScriptInstance is an instance of the variable.
mark as answered
pragma strict
function Start () {
}
var enabledState:boolean=true;var vuforiaVisible:boolean=false;
function Update () {
}
error Assets/b2.js(33,29): BCE0005: $$anonymous$$ identifier: 'myScript'.
Assets/b2.js(33,52): BCE0005: $$anonymous$$ identifier: 'myScript'.
var myObject : GameObject; var yourScriptInstance : $$anonymous$$yScriptName;
function Start(){ myObject = GameObject.Find("$$anonymous$$pot"); yourScriptInstance=myObject.GetComponent($$anonymous$$yScriptName); //$$anonymous$$yScriptName is your script with var enabledState:bool=true;var vuforiaVisible:bool=false; }
function Update () { if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){ if (guiTexture.HitTest(Input.GetTouch(0).position)){ if(yourScriptInstance.vuforiaVisible)
{
myObject.renderer.enabled = myScript.enabledState!=myScript.enabledState; } }
} }
The other script is attach to the 3D $$anonymous$$pot, the script name is $$anonymous$$yScriptName. Is this one
pragma strict
function Start () {
}
var enabledState:boolean=true;var vuforiaVisible:boolean=false;
function Update () {
}
you just need to change the if statement i mentioned in my answer.
Is that not working for you?
You have 'myScript.enabledState != myScript.enabledState' first off, this will always be false, second, you never defined 'myScript'
Your answer
Follow this Question
Related Questions
[Edited]-Android-swap position on touch 1 Answer
Drag an object to touch position(Problem) 1 Answer
iOS multiTouch / release - Strange problem 0 Answers
rect.Contains problem? 2 Answers
Taking Input from Android phones 1 Answer