OK, this is most likely an easy one.
I have a gameObject with 10 children (asteroid meshes).
I have a script that “targets” any of the 10 children successfully (prints debug.log msgs saying “Asteroid Targeted”).
I also have an “AsteroidLogic” script (the targeting script reads data from this). Basically, all the Logic script does is give you a composition percentage of the asteroid (e.g: 60% noble content).
I have two problems:
1.) How do I make it so that clicking on EACH asteroid gives me DIFFERENT random values? Currently, they’re ALL saying %36 percent, or ALL saying 80%. Each roid should be different.
2.) How do I STORE these values? Should I store them in the parent object? Correlate them to unique gameObject ids? Use an array? Hash table? When I say “STORE”, I mean if someone leaves the asteroid field, and it is destroyed – but they later return to the same field. Once the prefab is re-instantiated, Ideally the values should be the same as the last visit.
I’ll point out that these two scripts are the product of other Unity Answers/Forums threads, and while they might be cool, I assure you I am not very good at this, so to get to this point was a miracle to say the least.
TARGET SCRIPT:
// Found at:
// http://forum.unity3d.com/threads/84582-Enemy-health-only-to-appear-when-target-is-clicked-on.
static var playerTarget : Transform;
function Update() {
//check if the left mouse has been pressed down this frame
if (Input.GetMouseButtonUp(0)) {
//empty RaycastHit object which raycast puts the hit details into
var hit : RaycastHit;
//ray shooting out of the camera from where the mouse is
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, hit, 55000)){
if (hit.collider.gameObject.CompareTag("Asteroid")) {
//print out the name if the raycast hits something
playerTarget = hit.collider.transform;
var mf: MeshFilter = playerTarget.GetComponent(MeshFilter);
bounds = mf.mesh.bounds;
corners = new Vector3[8];
var asteroidLogic : AsteroidLogic = gameObject.GetComponent("AsteroidLogic");
var objectName : AsteroidLogic = gameObject.GetComponent("AsteroidLogic");
Debug.Log( playerTarget.name + " is " + asteroidLogic.worthyCompoundRemainder + " percent noble, " + hit.distance + " meters." );
}
else {
Debug.Log(hit.collider.name + " no tag");
}
}
}
}
ASTEROID LOGIC script:
static var worthyCompoundRemainder : int;
static var objectName : String;
static var inertCompoundPercentage = Random.Range(0, 100);
function Start () {
}
function Update () {
for(var n = 0; n < 10; n++) {
worthyCompoundRemainder = 100 - inertCompoundPercentage;
}
}
I would love any help, thanks!
PS - edited with help from Eric5h5 to be more visually pleasing.