'm New to use “Class”.
I’m trying to create a system which the objective is a points system for the NPC cars.
The script works but I just can not use as it should be in the GUI and PlayerPrefs class.
Whose purpose is to display the score of each car, the problem is I can not use the gui and correctly display the score of their car, and problem use PlayerPref to save and load the respective score of the car, a simple menu’s display NPC points obtained.
Not sure why, but it will be because of the class?
The scripts in Attach:
Attach “MainObject to gamobject player controller o car etc…”
1438825–77112–$MainClass.js (238 Bytes)
1438825–77113–$MainObject.js (841 Bytes)
It is easier if you paste the code here, instead of attaching files.
MainClass:
#pragma strict
// Class to call.
class MainJob {
// The currect car name to display.
var CarName : String = "Default";
// The currect car ID.
var CarID : int = 1;
// The currect car Points to get.
var CarPoints : int = 0;
}
MainObject:
#pragma strict
// Call the class script.
var mainClass : MainJob;
// The currect car ID to modify in the Inspector.
var curID : int = 1;
// The currect car Points to modify in the Inspector.
var currectPoints : int = 0;
// The currect car name to modify in the Inspector.
var Thename : String = "Barmy Army-";
function PointsSystem()
{
// The currect class variable (CarName).
mainClass.CarName = Thename;
// The currect class variable (CarID).
mainClass.CarID = curID;
// The currect class variable (CarPoints).
mainClass.CarPoints = currectPoints;
// Set currect points.
currectPoints ++;
// Debug Test only.
Debug.Log(mainClass.CarName +"curPoints! > " + mainClass.CarPoints + "carID " + mainClass.CarID);
}
function OnCollisionEnter(col : Collision) {
if (col.gameObject.tag == "COM")
{
PointsSystem();
}
}