What should I do? Then I connected with items in the game ?

I want player gather 1-100 Item to unlock but

i need (var PlayerDiamond) = connect with item in the game it player has collected.

What should I do? What I need to do ? DATABASE ?

my code for test

var nextLevel:String;
private var PlayerDiamond : int = 40;
var chapterUnlocked : boolean;
var chapterlocked : boolean;

function Start () {
 chapterUnlocked = (PlayerDiamond > 45);
  chapterlocked = (PlayerDiamond < 45);

}

function OnGUI ()
{
if (chapterlocked)
{ guiTexture.texture = texturelock;
  needitem.text = text; }




if (chapterUnlocked)
{ guiTexture.texture = textureunlock; }

}


function OnMouseUp ()
{
if(QuitButton)
{ Application.Quit(); }



else
{ Application.LoadLevel(nextLevel); }
}

Thank You !

1 Answer

1

From the code above, I assume you are not at the point of collecting objects. Typically objects are collected by either colliding with it, or by the user touching the screen. Getting an object by touching the screen is usually done through Physics.Raycast().

Usually the information about object in a game is stored with the object. The two most common are Tags and placing a script on an object that has the information.

Both Raycasting and Colliding give you the game object that you “touched.” From there both the tag and any scripts are available. See: Accessing Other Game Objects. Once you have access to either the tag or the component, you can decide if the object is one that should increment your PlayerDiamond variable.