- Home /
The question is answered, right answer was accepted
How do I stop an object from cloning when moving?
I'm creating a mobile game that the user has to tap the screen to move the object/character. Right now I'm using mouse input to test the game play and haven't gotten far in development, just getting the input down but I can't seem to figure it out. When I press play then click on the screen, the object moves to the clicked position but leaves a trail of self clones and it continues to do it every time I click. Help is greatly appreciated.
public class PlayerInput : MonoBehaviour
{
private Vector3 target;
public float speed = 1.5f;
// Use this for initialization
void Start ()
{
target = transform.position;
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target.z = transform.position.z;
//Debug.Log("TAP!!!");
}
gameObject.transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
}
}
Never$$anonymous$$d. It's gotta be a graphics issue.
HEY, take a screenshot of you camera object selected, check your flag settings of the camera, just like yemachu said, i doubt its a graphics issue
Answer by Mr. Mud · Feb 07, 2015 at 11:27 AM
From what I can make out of the image, the Clearflags of your camera are either set to "Depth only" or "Don't Clear".
Changing it to "Solid Color" or "Skybox" should solve this issue. Or have another camera render a background first... not all that efficient.
Yea the clear flags where set to depth only. Sorry about that. Thanks for the help.
This forum is supposed to help you out with some (slight) issues you might run into, so there is no need to apologize. In any case, I am glad that I could help you solve this issue.
Follow this Question
Related Questions
Unity3d 4,script nGUI btn drag convert to move where i mouse click 1 Answer
Get general direction of mouse/tap location relative to player on mouse click? 0 Answers
Smooth Camera Movement script with problem. 0 Answers
Getting object to follow mouse position along X axis only 4 Answers
c# scripting navigation problems 1 Answer