Hello
i attached the below script to an empty gameobject for spawning prefabs it works fine but the only problem is that i don’t know how to set xMin and xMax position that will be able to change by it self xMin and xMax position when the screen size is changed.
Note: some prefabs are having circleCollider, and some of them BoxCollider.
thank you in advance!!!
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class SpawningColors : MonoBehaviour
{
public GameObject[] ColorSprites;
public float delayTimer = 0.5f;
public float xMaxPosition, xMinPosition;
private float timer;
private int colorObjectNumbers;
// Use this for initialization
void Start ()
{
timer = Time.deltaTime;
}
// Update is called once per frame
void FixedUpdate ()
{
Spawning ();
}
public void Spawning ()
{
timer = timer - Time.deltaTime;
if (timer <=0)
{
Vector3 scale = ColorSprites[colorObjectNumbers].transform.localScale;
float rndmScale = Random.Range (0.8f, 1f);
scale = new Vector3 (rndmScale, rndmScale, rndmScale);
ColorSprites[colorObjectNumbers].transform.localScale = scale; // assign the new scale.
Vector3 colorObjectPos = new Vector3 (Random.Range(xMinPosition, xMaxPosition),transform.position.y, transform.position.z );
colorObjectNumbers = Random.Range(0, 24);
Instantiate(ColorSprites[colorObjectNumbers], colorObjectPos, transform.rotation);
timer = delayTimer;
}
}
}