Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

Unity random mesh spawner at certain position C# script

Posted on August 31, 2024August 31, 2024 by Habibie

In this blog post I will share a simple script that I’ve made to randomize what game object to be instantiated at a certain position as a child game object.

For example, a car game object needs random accessories to be instantiated at certain area of the car… bla bla bla.

This is the script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RandomMeshSpawner : MonoBehaviour
{
	
	public List<GameObject> meshes;
	public Transform refTransform;
	
    // Start is called before the first frame update
    void Start()
    {
        GameObject omesh = Instantiate(meshes[Random.Range(0, meshes.Count-1)]) as GameObject;
		omesh.transform.SetParent(gameObject.transform, false);
		omesh.transform.localPosition = refTransform.localPosition;
		omesh.transform.localScale = refTransform.localScale;
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

How to use the script? Check out my video below:

Post Views: 413
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
  • Advanced Blinking Marker Script to show objects position in your game canvas
  • Ciihuy Images Merger – Fast & Easy Online Image Combiner
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme