How to chanege the positionon of the cube when touching the screen?
Hello I am building an Android game and I am struggling to move the position of clicked cube what I am trying to do is this : -When I am dragging finger on the screen and I am over a cube it should change its position (move 1 block in front of) -When I release finger the cube should return to its original position after 3 seconds in the same order I dragged my finger
I tried with this code but it is not working:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneOneScript : MonoBehaviour {
public GameObject particle;
void Update()
{
foreach (Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
// Construct a ray from the current touch coordinates
Ray ray = Camera.main.ScreenPointToRay(touch.position);
if (Physics.Raycast(ray))
{
// Create a particle if hit
transform.Translate(0, 0, 1);
}
}
}
}
}
The game logic is: There are going to be balls falling in front of the cubes with locked Z Position and the player should click over cubes(they move on Z position ) to come in front of to save the balls from falling in the wrong direction and after 3 seconds the cubes return to its normal state in the wall where they have been before the touch from the screen.