- Home /
I need help with an error
this is the error i get within unity
(74,36): BCE0120: 'hudController.coin' is inaccessible due to its protection level.
and this is the script
enum PickupType { Grow = 0, Key = 1, Coin = 2, Fireball = 3, ExtraLife = 4, GameTime = 5, }
var pickupType = PickupType.Grow; var pickupValue : int = 1; var itemParticle : Transform; var soundItemPickup : AudioClip; var soundDelay : float = 0.0; var soundRate : float = 0.0;
private var playerGameObject : GameObject; private var hudGameObject : GameObject; private var extraLifeEnable : boolean = false;
function Start () { playerGameObject = GameObject.FindWithTag ( "Player" ); hudGameObject = GameObject.FindWithTag ( "hud" ); } function OnTriggerEnter ( other : Collider ) { if ( other.tag == "collisionBoxBody" ) { var pProp = playerGameObject.GetComponent ( playerProperties );
ApplyPickup ( pProp );
renderer.enabled = false;
if ( itemParticle )
{
Instantiate ( itemParticle, transform.position, transform.rotation );
}
if ( soundItemPickup )
{
PlaySound ( soundItemPickup, 0 );
}
yield WaitForSeconds ( audio.clip.length );
if ( extraLifeEnable )
{
pProp.lives += pickupValue;
extraLifeEnable = false;
}
Destroy ( gameObject );
}
} function ApplyPickup ( playerStatus : playerProperties ) { var hudConnect = hudGameObject.GetComponent ( hudController );
switch ( pickupType )
{
case PickupType.Grow:
if ( playerStatus.playerState != PlayerState.MarioFire)
{
playerStatus.playerState = PlayerState.MarioLarge;
playerStatus.changeMario = true;
}
break;
case PickupType.Key:
playerStatus.AddKey ( pickupValue );
break;
case PickupType.Coin:
playerStatus.AddCoin ( pickupValue );
hudConnect.coin += pickupValue;
break;
case PickupType.Fireball:
playerStatus.playerState = PlayerState.MarioFire;
playerStatus.hasFire = true;
playerStatus.changeMario = true;
break;
case PickupType.ExtraLife:
extraLifeEnable = true;
break;
case PickupType.GameTime:
// playerStatus.AddTime ( pickupValue );
break;
}
} function PlaySound ( soundName, soundDelay ) { if ( !audio.isPlaying && Time.time > soundRate ) { soundRate = Time.time + soundDelay; audio.clip = soundName; audio.Play (); } }
Answer by aldonaletto · Sep 14, 2011 at 12:17 AM
Probably coin is a private variable of hudController - you should declare it as public to be accessible outside the script.
Yes that worked thank you very much to much time looking at lines of code will make you think everything is spelled wrong too...lol
This would not produce an error in Unity 3.3, but Unity 3.4 became smarter and now flags these scope errors. Lucky us that I read this when searching in the "What's New in 3.4" doc for another modification (which I never found...)
By the way, @Durante, if this answer solved your problem, please click the "check" button below the voting thumbs to mark it as accepted - the question becomes green and may help others having the same problem.
Answer by PatHightree · Sep 13, 2011 at 10:52 PM
Try :
public enum PickupType { Grow = 0, Key = 1, Coin = 2, Fireball = 3, ExtraLife = 4, GameTime = 5, }
Answer by Durante · Sep 14, 2011 at 12:09 AM
@ PatHightree
that ddnt work but thank you for your help,@PatHightree
it ddnt work but i greatly app. you trying.
@Durante, please don't use the Your Answer box to post replies or comments - use the add new comment at the question/answers ins$$anonymous$$d. UA is different from forums: answers are for the question only (they are counted) - everything else must be posted with add new comment
Your answer
Follow this Question
Related Questions
Assets/Scripts/PlayerController.cs(22,25): error CS8025: Parsing error 0 Answers
need help, with greater than statment 1 Answer
Another Null Reference Exception 0 Answers
Destroy Other 2 Answers
Can't get rid of errors 0 Answers