Trouble with static typing

Oh helloes! Long time reader, first time poster.
I’m having a problem with static casting when I switched my project to an iOS environment. Didn’t think this at the time when I was coding with the windows version (works fine there), but I realize now that I should use #pragma strict.

The problem is, that when I try to call other gameobject script’s function I get compile errors like:
BCE0019: ‘isDead’ is not a member of ‘UnityEditor.PlayerSettings’.

I’m a bit puzzled and can’t find the solution :frowning:
Here’s what I’ve got this far:

CameraStuff2.js:

#pragma strict
var pallo : GameObject;
var speed = 100;
private var playerConf : PlayerSettings;


function SwitchCollider()
{	
	if (playerConf.isDead() == 0)
	{
		if(pallo.GetComponent(Collider).GetType()==SphereCollider){
			Destroy(pallo.GetComponent(Collider));			
			pallo.AddComponent("BoxCollider");
		}
		else
		{
			Destroy(pallo.GetComponent(Collider));			
			pallo.AddComponent("SphereCollider");
		}
	}
}

function Awake()
{
	playerConf = GameObject.Find("Player").GetComponent("PlayerSettings") as PlayerSettings;
}

function Update ()
{
	transform.position.x = pallo.transform.position.x;
	transform.position.y = pallo.transform.position.y;
	
	if (Input.GetKey (KeyCode.Space))
	 	SwitchCollider();
	 
	if (Input.GetKey (KeyCode.LeftArrow))
		transform.Rotate(Vector3.back * Time.deltaTime * speed);
	if (Input.GetKey (KeyCode.RightArrow))
		transform.Rotate(Vector3.forward * Time.deltaTime * speed);
}

PlayerSettings.js

#pragma strict
private var startLocation : Vector3;
private var playerDead;

public function setDead(x)
{
	playerDead = x;
}
public function isDead()
{
	return this.playerDead;
}

function Awake()
{
	this.playerDead = 0;
	this.startLocation = Vector3.zero;
}

Maybe try explicitly typing playerDead and isDead, eg:

#pragma strict
private var startLocation : Vector3;
private var playerDead [B]: int[/B];

public function setDead(x)
{
	playerDead = x;
}
public function isDead() [B]: int[/B]
{
	return this.playerDead;
}

function Awake()
{
	this.playerDead = 0;
	this.startLocation = Vector3.zero;
}

Nope. Good point, but gives the same error.

Weird. I don’t use pragma strict too much, but maybe you can’t use functions as comparisons for some reason? Did you try storing it in a local var? like:

var isDead : int = playerConf.isDead();
if (isDead == 0)

Tried it but results are the same :confused: the error still occurs with the function call

OH! funny thing, there’s already PlayerSettings class in unity, so that’s why it couldn’t find my member function. case solved, but lots of type casting still to do :slight_smile:

Hah! I never would have figured that out.