- Home /
getcomponent' is not a member of 'object'
getting this error whan compiling on android, but works fine on windows. please give me some alternative way to correct this error. tnx.
for (var checkDoor : GameObject in cells[i].GetComponent(AIpathCellScript).doors)
What is the variable type of cells array? If you haven't explicitly given it a type, you should give it the type GameObject, Android forces strict program$$anonymous$$g, compiler won't choose a type for you and select Object as it's type most of the time. You can also put #pragma strict at the top of each javascript to encounter same errors before switching the project to Android.
Put #pragma strict at the top of your files and it will tell you what variables you haven't defined - this is necessary for droid but not for windows. What is cells defined as?
Also, is 'GetComponent(AIpathCellScript).doors' a GameObject? That's how you're treating it.
this is the full code. can you do something about it?
var cells = new Array();
var doorsToCells = new Array();
var imediateCells = new Array();
var testForCells : boolean = true; //
var waitToTestCells : float = 2; //
var stage : int = 1;
@HideInInspector
var doorOpen : boolean = true;
function Awake ()
{
doorOpen = true;
cells = GameObject.FindGameObjectsWithTag("AIpathCell");
doorsToCells.length = cells.length; //
testForCells = true;
waitToTestCells = 2;
stage = 1;
}
function Update ()
{
if (testForCells && waitToTestCells <= 0)
{
for (var imediateCell : GameObject in imediateCells)
{
for (var i : int = 0; i <= cells.length - 1; i++)
{
if (cells[i] == imediateCell) //
doorsToCells[i] = 1;
}
}
for (stage = 2; stage <= cells.length; stage++)
{
for (i = 0; i <= cells.length - 1; i++) //
{
if (doorsToCells[i] == stage - 1)
for (var checkDoor : GameObject in cells[i].GetComponent(AIpathCellScript).doors)
{
if (checkDoor != gameObject)
{
for (var checkCell : GameObject in checkDoor.GetComponent(AIpathDoorScript).imediateCells)
{
for (var j : int = 0; j <= cells.length - 1; j++)
{
if (cells[j] == checkCell && doorsToCells[j] == null)
doorsToCells[j] = stage;
}
}
}
}
}
}
testForCells = false;
}
waitToTestCells -= 1;
}
function OnTriggerEnter (other : Collider)
{
if (other.tag == "AIpathCell")
imediateCells.Add(other.gameObject);
}
Answer by Eric5h5 · Sep 19, 2012 at 05:35 PM
Presumably your "cells" array is done with the JS Array class, or possibly an ArrayList. It will make things faster and easier if you ditch the Array class (and ArrayList) and always use built-in arrays or generic Lists instead.
Answer by SarperS · Sep 19, 2012 at 05:36 PM
You should use built in arrays instead of the Array class if you don't need to resize them in realtime. And in that case you can use Generic lists. So use this;
var doorsToCells : GameObject[];
var imediateCells : GameObject[];
this is the whole code, can you do something here? var cells = new Array ();
var doorsToCells = new Array(); var imediateCells = new Array(); var testForCells : boolean = true; // var waitToTestCells : float = 2; // var stage : int = 1; @HideInInspector var doorOpen : boolean = true;
function Awake ()
{
doorOpen = true;
cells = GameObject.FindGameObjectsWithTag("AIpathCell");
doorsToCells.length = cells.length; //
testForCells = true;
waitToTestCells = 2;
stage = 1;
}
function Update ()
{
if (testForCells && waitToTestCells <= 0)
{
for (var imediateCell : GameObject in imediateCells)
{
for (var i : int = 0; i <= cells.length - 1; i++)
{
if (cells[i] == imediateCell)
doorsToCells[i] = 1;
}
}
for (stage = 2; stage <= cells.length; stage++)
{
for (i = 0; i <= cells.length - 1; i++) //
{
if (doorsToCells[i] == stage - 1)
for (var checkDoor : GameObject in cells[i].GetComponent(AIpathCellScript).doors)
{ if (checkDoor != gameObject)
{
for (var checkCell : GameObject in checkDoor.GetComponent(AIpathDoorScript).imediateCells)
{
for (var j : int = 0; j <= cells.length - 1; j++)
{
if (cells[j] == checkCell && doorsToCells[j] == null)
doorsToCells[j] = stage;
}
}
}
}
}
}
testForCells = false;
}
waitToTestCells -= 1;
}
function OnTriggerEnter (other : Collider)
{
if (other.tag == "AIpathCell")
imediateCells.Add(other.gameObject);
}
Your answer
Follow this Question
Related Questions
Script stops working when switching to Android 1 Answer
How can i get a Transform component from an other object's script? 1 Answer
Object Refererence not set yada yada... 2 Answers
How do I change Sprites (and manipulate the Sprite Object) in C#? 0 Answers
Animating an object so it doesn't bounce to the initial location the animation was recorded 1 Answer