execute for x seconds <how?>

hello

I want to know how many ways are there to execute a command for 5 seconds for example.

second 0 : a = 1
second 1 : a = 2
second 2 : a = 3
second 3 : a = 4
second 4 : a = 5
second 5 : a = 6
second 6 : a = 6
second 7 : a = 6
.
.
.

how many ways are there, easy and hard ones.

The answer is “lots” because the question is too broad and mostly meaningless.

thanks, ok, I want a command to get executed [ON] for x seconds then it is [OFF] , clear now?

//delay
delay = 10;

//store current time in a variable
startTime = Time.time;

…

//Time.time is current time
if (Time.time >= (startTime + delay))

…

   void Update()
    {
        if(actionON == true)
            Do Action;
    }

    IENumerator TimedAction()
    {
        actionON = true;
        yield return new WaitForSecond(5);
        actionON = false;
    }

And you need something to launch the coroutine like a button:

void OnGUI()
    {
        if (GUI.Button(Rect, ""))
        {
            StartCoroutine("TimedAction");
        }
    }

line 47 brings an error

using UnityEngine;
using System.Collections;

public class MoveObjectAsTouch : MonoBehaviour 
{
	
	public string MovableObjectTag;	//Disk
	
	private Transform _myTransform;
	
	private string _currentState;
	
	private Ray _ray;
	
	private RaycastHit _hit;
	
	private bool _rightObject;
	
	private Vector3 _initialPos;
	private Vector3 screenPos;
	private Vector3 offset;
	private Vector3 currentScreenPos;
	private Vector3 currentPos;
	private Vector3 F1;
	private Vector3 F2;
	private Vector3 M;

	
	void Start()
	{
		_myTransform = transform;
	}
	
	void OnGUI()
	{
		//GUI.Label(new Rect(10, 10, 100, 30), _currentState);
	}
	
	void FixedUpdate()
	{
		//////
		{
        if(actionON == true)
            print("launch");
    	}
		
		IENumerator TimedAction()
   		{
        	actionON = true;
        	yield return new WaitForSecond(5);
        	actionON = false;
  		}
		//////

		if (iPhoneInput.touchCount == 1)
		{

            Touch firstTouch = Input.GetTouch(0);
            Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
            RaycastHit hit;

            if (Physics.Raycast (ray, out hit, 200)) 
			{
                if(hit.collider.tag == MovableObjectTag)
				{
                    if (firstTouch.phase == TouchPhase.Began) 
					{
						_currentState = "Touch's began";
						
                        screenPos = Camera.main.WorldToScreenPoint(_myTransform.position);
                        offset = _myTransform.position - Camera.main.ScreenToWorldPoint(new Vector3(firstTouch.position.x,firstTouch.position.y,screenPos.z));   
					}
					else if(firstTouch.phase == TouchPhase.Moved)
					{
						_currentState = "Touch's Moved";
						
                        currentScreenPos = new Vector3(firstTouch.position.x, firstTouch.position.y, screenPos.z); // firstTouch.position.y
                        currentPos = Camera.main.ScreenToWorldPoint(currentScreenPos) + offset;
                        _myTransform.position = currentPos;
                	}
					else if(firstTouch.phase == TouchPhase.Ended)
					{
						_currentState = "Touch's Ended";
						 StartCoroutine("TimedAction");
						//rigidbody.isKinematic = false;
						
					}
            	}   
        	}       
   	 	}
	}
}
  1. its IEnumerator not IENumerator.
  2. You have a method TimedAction -inside- another method FixedUpdate