iOS Follow Finger C#

Hi gurlz and dudes!

I have to repost this as the last thread broke :confused: so sorry for the same question.

I’m trying to make a cube follow a finger touch on iPad. Ive got it working in the debug but cant work out how to attach it to the cube with the correct syntax.

What am i doing wrong?

I believe it’s this line screwing up:

theCube.transform.position = Vector3(theCube.transform.position, (Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x,touch.position.y,3f))), step);

This is the full script:

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

public float speed = 4;
private GameObject theCube;


void Start(){
	theCube = GameObject.Find("Cube");
}

    void Update() {
        int fingerCount = 0;
        foreach (Touch touch in Input.touches) {
        	float step = speed * Time.deltaTime;
            if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
                
                print(Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x,touch.position.y,3f)));

                theCube.transform.position = Vector3(theCube.transform.position, (Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x,touch.position.y,3f))), step);
            
        }

        
    }
}

It “broke”? Do you talk about your question that has been moved into the help room over here?

I guess your line should look like this:

theCube.transform.position = Vector3.Lerp(theCube.transform.position, (Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x,touch.position.y,3f))), step);