Question by 
               riberodrigo · Feb 17, 2017 at 07:35 PM · 
                script.movingsameindependent  
              
 
              Como posso mover GameObjects de mesmo script de forma independente?
Criei um script o qual faz um GameObject se mover de forma senoidal. O movimento ocorre perfeitamente, mas quando mais de um GameObject contendo este script está em cena todos se movem como um espelho um do outro e não de forma relativa, deixando o jogo muito artificial. Tentei usar posicionamento local e mesmo assim não consegui resolver o problema. Eis o código:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Enemy4 : Nave {
 public float horizontalSpeed;
 public int yFactor;
 private float count = 3;
 private Vector3 s;
 private bool setPos = false;
 private float x;
 private float y;
 // Use this for initialization
 void Start () {
     x = 0;
     y = 0;
     s = transform.position;
     side = Side.defside.ENEMY;
 }
 
 // Update is called once per frame
 void Update () {
     y += yFactor * Time.deltaTime;
     x = Mathf.Sin (Time.time) * horizontalSpeed;
     transform.position = s + new Vector3 (x,y, 0);
 }
     
 
               }
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Stop movement on collision 1 Answer
What is the best way to make moving obstacles in a 3d game? 0 Answers
call same script on different objects 0 Answers
Teleportation with gun 2 Answers