M
M
Max Bogachov2017-03-17 20:32:02
Game development
Max Bogachov, 2017-03-17 20:32:02

Unity how to remove duplicate objects?

When I press W, only the object is duplicated (the player, but only visually), and when I attached the camera, the surrounding objects themselves were duplicated!
Here is the code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class moving : MonoBehaviour {
  public GameObject obj;
  private float speed = 5f;
  private Rigidbody2D rb;
  private Vector3 directionY;

  private void Awake(){
    rb = GetComponent <Rigidbody2D> ();
  }

  private void Update () {
    if (Input.GetKey (KeyCode.W)) {
      directionY = transform.up;
      transform.position = Vector3.MoveTowards (transform.position + directionY, transform.position,speed * Time.deltaTime);
    } else if (Input.GetKey (KeyCode.D)) {
      
    }

  }
}
7bdd06c6635047c1b5de05cca6908053.jpge810a1417c1049e0a9ed76003fac0031.jpg8fc652483b0143aba18c724dea531e21.jpg3015f6b26f994c92a08c12a1686823c0.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Basmanov, 2017-03-18
@Geekinder

You have "Depth only" or "Don't Clear" on your camera 's clearFlags , so all your objects draw plumes. Install Solid Color or Skybox, then there will be no such problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question