Hi guys,
I’m designing a welcome screen to my game and I want the GameObjects to move out from screen at a constant speed with a simple click:
So, what I want is to click anywhere in the screen and move the cogs at a constant speed to make them disappear from screen. Here’s my script attempt:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StartScreen: MonoBehaviour
{
public GameObject leftCog1;
public GameObject leftCog2;
public GameObject rightCog1;
public GameObject rightCog2;
public GameObject welcomText;
public void Update(){
float speedleft = -1;
float speedright = 1;
if(Input.GetKey(KeyCode.Mouse0)){
leftCog1.transform.Translate (speedleft,0,0);
leftCog2.transform.Translate (speedleft,0,0);
rightCog1.transform.Translate (speedright,0,0);
rightCog2.transform.Translate (speedright,0,0);
}
}
}
It works as long as I keep pressed the left mouse button, but I want this to happen “forever”. If I know how to do this, then I will be able to tune up the code, but I need to move these cogs at a constant speed with just one click.
Any hints?
Thanks!