how to random rotation in unity code example
Example: how to make random Transform point in unity
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Spawn : MonoBehaviour { public Transform[] array = new Transform[5]; int random; public GameObject generate; public Transform Target; // Use this for initialization void Start () { random = Random.Range(0, array.Length); Spawner(); } void Spawner() { GameObject clone = Instantiate(generate, array[random].transform.position, array[random].transform.rotation) as GameObject; Vector2 origin = clone.transform.position; Vector2 target = Target.position; // Vector2 direction = new Vector2(target.x - origin.x, target.y - origin.y); clone.transform.up = direction; clone.GetComponent<Rigidbody2D>().AddRelativeForce(Vector2.up * Time.deltaTime * 100 * 8); } // Update is called once per frame void Update () { } }