Question by
riberodrigo · Feb 17, 2017 at 01:34 PM ·
objectsmoveindependentsin
How to make multiple objects with the same script work independently?
I created a script for sinusoidal motion. The movement works perfectly, but the various objects with this script do not move independently. What could I do to solve this problem?
Here is the script:
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
click and move script no working (as intended) 0 Answers
How can i make an object (a cube) change the surface or plan of the game? 2 Answers
[yes / no question] Move objects WITH the terrain 1 Answer
Need this Object to move faster and faster after time! 2 Answers
How to move object a from in front of object b to in front of object c and transfer orientation? 1 Answer