Quantcast
Viewing latest article 18
Browse Latest Browse All 102

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); } }

Viewing latest article 18
Browse Latest Browse All 102

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>