How do I instantiate a prefab with scale? Update 1.2 (SOLVED)

Thank you, Guys! With your help, I found out that first make all kinds of master prefabs from importing it to the project folder. Like a prefab for the Ghost shape, a prefab for Scale Shape and Display shape. Once the Prefab is in the scene and you need to use a prefab for Instantiate; bring 2 things to make a Unity prefab and not a master prefab. And those to things are:

An empty game Object meant for scaling when Instantiating

A Game object underneath scaling empty game object for display. But now set up for finalizing plant shapes and change to the finalized material to a final.

Then bring the whole group to the project folder to make it a non-master prefab. Last, bring it to the reference script to instantiate the new non-master prefab in the project folder.

The best way explaining is kept creating non-master prefabs until you reach to the prefab with an empty game object meant for scaling a finalized shape connect to the scale empty game object underneath. Looks like it’s solved. :smiley:

It’s been 2 months me working on my game it’s looking good. :smiley:

When you instantiate the object, grab a reference to it :

GameObject go = Instantiate (plantShapeGO, transform.position, transform.rotation, plantShapeGO.transform.parent);

And then set the scale of the object.

go.transform.localScale = new Vector3(/*scale stuff*/);

This is how I scale the zombies in my game to add some variety.

REMOVED OLD STUFF


The gameObject you are copying is in the scene already, so when you scale that gameObject, anything you instantiate from it, will be an exact clone (transform wise: scale, position, whatever).


You need to link the prefab from the project folder, not link the gameObject in the scene to be copied. It’s possible you didn’t even make a prefab. If you didn’t, drag the gameObject to be copied from the scene, into a prefab folder in your project. Now you have a prefab (it becomes blue - at least in the higher version of Unity). Link this one in the reference to be copied.


It’ works, but that’s not what I really wanted. ^^’ I forgot to say that when I scale the ghost GameObject with the arrow keys. Then press keypad enter it instantiates the same size with the ghost game object. Here is the scaling Script I made. But I have no idea how Instantiate the same size with the scale from the ghost gameobject? Do you guys know?

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

public class PracticeGOScaling : MonoBehaviour 
{
	[SerializeField] public Transform target;
	[SerializeField] public float angle1 = 0.0f;
	[SerializeField] public float angle2 = 179.9f;


	private void Awake()
	{
		angle1 = 0.0f;
		angle2 = 179.9f;
	}

	void Update()
	{
		Scale ();
	}

	void Scale () 
	{
		Vector3 targetDir = target.position - transform.position;
		float angle1 = Vector3.Angle (targetDir, transform.forward);
		float angle2 = Vector3.Angle (targetDir, transform.right);

		if (Input.GetKeyDown (KeyCode.UpArrow)) 
		{
			if (angle1 >= 135.0f ) 
			{
				transform.localScale += new Vector3(0, 0 ,-1);
			}
			if (angle1 <= 45.0f ) 
			{
				transform.localScale -= new Vector3(0, 0 ,1);
			}
			if (angle2 >= 135.0f ) 
			{
				transform.localScale += new Vector3(-1, 0 ,0);
			}
			if (angle2 <= 45.0f ) 
			{
				transform.localScale -= new Vector3(1, 0 , 0);
			}
		}
		if (Input.GetKeyDown (KeyCode.DownArrow)) 
		{
			if (angle1 >= 135.0f) {
				transform.localScale -= new Vector3(0, 0 ,-1);
			}
			if (angle1 <= 45.0f) {
				transform.localScale += new Vector3(0, 0 ,1);
			}
			if (angle2 >= 135.0f) {
				transform.localScale -= new Vector3(-1, 0 ,0);
			}
			if (angle2 <= 45.0f) {
				transform.localScale += new Vector3(1, 0 ,0);
			}
		}
		if (Input.GetKeyDown (KeyCode.LeftArrow)) 
		{
			if (angle1 >= 135.0f) {
				transform.localScale -= new Vector3(1, 0 ,0);
			}
			if (angle1 <= 45.0f) {
				transform.localScale += new Vector3(-1, 0 ,0);
			}
			if (angle2 >= 135.0f) {
				transform.localScale += new Vector3(0, 0 ,-1);
			}
			if (angle2 <= 45.0f) {
				transform.localScale -= new Vector3(0, 0 ,1);
			}
		}
		if (Input.GetKeyDown (KeyCode.RightArrow)) 
		{
			if (angle1 >= 135.0f) {
				transform.localScale += new Vector3 (1, 0, 0);
			}
			if (angle1 <= 45.0f) {
				transform.localScale -= new Vector3 (-1, 0, 0);
			}
			if (angle2 >= 135.0f) {
				transform.localScale -= new Vector3 (0, 0, -1);
			}
			if (angle2 <= 45.0f) {
				transform.localScale += new Vector3 (0, 0, 1);
			}
		}
		if (Input.GetKeyDown (KeyCode.Minus)) 
		{
			transform.localScale += new Vector3 (0, -1, 0);
		}
		if (Input.GetKeyDown (KeyCode.Plus)) 
		{
			transform.localScale += new Vector3 (0, 1, 0);
		}
		if (Input.GetKeyDown (KeyCode.Comma)) 
		{
			transform.localScale += new Vector3 (0f, -0.1f, 0f);
		}
		if (Input.GetKeyDown (KeyCode.Period)) 
		{
			transform.localScale += new Vector3 (0f, 0.1f, 0f);
		}
		if (Input.GetKeyDown (KeyCode.N)) 
		{
			transform.localScale += new Vector3 (0f, -0.01f, 0f);
		}
		if (Input.GetKeyDown (KeyCode.M)) 
		{
			transform.localScale += new Vector3 (0f, 0.01f, 0f);
		}
	}
}

Wait a Minute?.. Why not make assets shapes with all kinds of shapes and sizes? Using the mouse scroll wheel or make a Inventory. Basically I am trying to make my own Blockland game. I call it Steels Sandbox Mod Ver 1.0 . Any Tutorials on this genre?