Am I Overdoing things?

Hi there.
I’m making a shooting range game prototype. I made a target block. What i’m trying to do is move upwards wait 3 seconds or until shot then move to position. It must be easy but geez it wasn’t. Somehow i managed to make this but i’m confused and think i’m overthinking.

    public float moveSpeed = 3;
    private float _speed;
    private float waitTime = 3;
    private float nextTime = 0;
    
    void Awake()
    {
        
        _speed = moveSpeed;
    }
	
	void Update () 
    {

        float amtMove = _speed * Time.deltaTime;
        transform.Translate(Vector3.up * amtMove);

        if ((int)transform.position.y == 5)
        {
            StartCoroutine("WaitforShoot");
            
        }

        if (transform.position.y < 0)
        { 
            StopMove();
            StopCoroutine("WaitforShoot");
        }

        if (Input.GetKeyDown("c"))
        {
            StopCoroutine("WaitforShoot");
            MoveDown();
        }

	}


    

    void MoveUp()
    {

        _speed = moveSpeed;
    }

    void StopMove()
    {
        _speed = 0;
    }

    public void MoveDown()
    {
        _speed = -moveSpeed;
    }

    IEnumerator WaitforShoot()
    {
        StopMove();
        yield return new WaitForSeconds(3);
        MoveDown();
       
    }

}

I don’t quite get what you are trying to do.

please ignore nextTime and waitTime variables.

target moves up
target waits for 3 seconds or until get shot
then move back to old position.

like this Discover and Play Free Online Games on Kongregate!

Just use Animation Editor.

http://unity3d.com/support/documentation/Manual/Animation.html

Ah i understand :slight_smile: i was overthinkg. So basically, play “moving up animation” then wait for shot or 3 seconds then play “moving down animation” right?

No, you can make it much simpler. You shouldn’t need to do any waiting or co-routines at all via script.

Please read/work thought all the manual pages in that animation section. You should be able to do everything with 2 animations and one animation event. Only code you’d need would be the key capture, an if statement to check currently playing animation and to change it if it’s not already moving down.

Thanks.