Try like this:
var tempNum = PlayerTimerList.Count;
PlayerTimer.TimerName = tempNum.ToString();
that’s all you meant I believe
EDIT:
lucky for you, I got a bit carried away:
#pragma strict
import System.Collections.Generic;
class TimerClass
{
var TimerName : String;
var TimerTotal : float = 5.0 ;
var TimerActive : boolean = false;
var TimerRemain : float;
var TimerBox : Rect;
var TimerIndex : int;
}
var buttonRect : Rect = new Rect(50, 150, 100,30);
var PlayerTimer : TimerClass;
var PlayerTimerList : List.<TimerClass> = new List.<TimerClass >();
var snapToGrid : boolean;
var gridWidth : int = 50;
var gridHeight : int = 50;
function Start () {
buttonRect= new Rect(50, 150, 100,30);
PlayerTimer = null;
}
function Update () {
var inverseMousePosition = Input.mousePosition;
inverseMousePosition.y = Screen.height-inverseMousePosition.y;
for(timer in PlayerTimerList){
if(Input.GetMouseButtonDown(0) && timer.TimerBox.Contains(inverseMousePosition))
{
PlayerTimer = timer;
}
}
if(Input.GetMouseButtonDown(0) && buttonRect.Contains(inverseMousePosition))
{
if(PlayerTimer && PlayerTimer.TimerBox.Contains(inverseMousePosition))
Debug.Log("Override Button");
else
AddTimer();
}
if(Input.GetMouseButtonDown(1) && PlayerTimerList){
for(var i = 0; i < PlayerTimerList.Count;i++){
if(PlayerTimerList*.TimerBox.Contains(inverseMousePosition)){*
PlayerTimerList_.TimerActive = !PlayerTimerList*.TimerActive;
}
}
}
if(Input.GetMouseButton(0) && PlayerTimer){
if(!snapToGrid){
PlayerTimer.TimerBox.x = Input.mousePosition.x;
PlayerTimer.TimerBox.y = Screen.height-Input.mousePosition.y;
}
else
{
PlayerTimer.TimerBox.x = Input.mousePosition.x - (Input.mousePosition.x % gridWidth) ;
PlayerTimer.TimerBox.y = (Screen.height-Input.mousePosition.y) - ((Screen.height-Input.mousePosition.y) % gridHeight);
}
}*
if(Input.GetMouseButtonUp(0))
PlayerTimer = null;_
for(i = 0; i < PlayerTimerList.Count;i++){
if(PlayerTimerList*.TimerActive){*
if(PlayerTimerList*.TimerRemain >= 0)*
PlayerTimerList*.TimerRemain -= Time.deltaTime;*
else{
PlayerTimerList.RemoveAt(i); // This remove the timer
ReName();
}
}
}
}
function AddTimer ()
{
PlayerTimer = new TimerClass ();
PlayerTimer.TimerRemain = PlayerTimer.TimerTotal;
PlayerTimerList.Add(PlayerTimer);
var tempNum = PlayerTimerList.Count;
PlayerTimer.TimerName = tempNum.ToString();
PlayerTimer.TimerBox = new Rect(Input.mousePosition.x,Screen.height-Input.mousePosition.y,30,30);
}
function OnGUI ()
{
GUI.Box(Rect(buttonRect), “NEW TIMER”);
for (timer in PlayerTimerList){
GUI.Box(timer.TimerBox,timer.TimerName);
if (timer.TimerActive){
GUI.Label(timer.TimerBox,“!” + timer.TimerRemain);
}
}
}
function ReName(){
for(var i = 0; i < PlayerTimerList.Count;i++) // loop through each element of PlayerTimerList
{
PlayerTimerList*.TimerName = (i+1).ToString(); // Set name equal to current position in list (name is i+1)*
PlayerTimerList*.TimerIndex = i; //index is i*
}
}
This should give you a decent head start… it allows you to drag and place your timers! For now you can right click on one to start it… Enjoy
NOTE: Updated… fixed a few bugs, got rid of the needless coroutine…