using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
public class RandomPointInsideRectangle : MonoBehaviour
{
public GameObject prefab;
private void Update()
{
var scale = GetComponent<RectTransform>().rect.size / 2f ;
var x = Random.Range(-scale.x, scale.x);
var y = Random.Range(-scale.y, scale.y);
var spawn = Instantiate(prefab, transform);
spawn.transform.localPosition = new Vector3(x, y, 0);
}
}
Last active
November 26, 2019 10:21
-
-
Save smkplus/b449220ab1f485c8df03cf78503ac44f to your computer and use it in GitHub Desktop.
Random Inside RectTransform
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment