Question by
NicoloTrapasso · Dec 20, 2016 at 08:58 PM ·
playerspawnscale
Spawn player and scale
Hi, i'm a beginner and this is my script for spawn player. Whit this script i can spawn player, choose if i want to scale and choose if i want to spawn two player.
the actually situation is: -choose scaled -set value -play game -play the game with player scaled -stop the game -deselect scaled -play the game -play the game with player scaled -stop the game -play the game -play the game with normal player
this i what i want: -choose scaled -set value -play game -play the game with player scaled -stop the game -deselect scaled -play the game -play the game with normal player
What is the problem?
using UnityEngine; using System.Collections;
public class SpawnPlayer : MonoBehaviour {
public GameObject collectorPrefab;
public bool multiplayer = false;
public bool scaled = false;
public float scale = 1f;
void SpawnMultiPlayer1()
{
Instantiate(collectorPrefab);
collectorPrefab.transform.position = new Vector3(-5, 12);
collectorPrefab.transform.localScale = new Vector3(2, 2);
if (scaled == true)
{
//store scale of this transform in temporary variable
Vector2 temp = transform.localScale;
//change the values for this saved variable (not actual transform scale)
temp.x = scale;
temp.y = scale;
//assign temp variable back to transform scale
collectorPrefab.transform.localScale = temp;
collectorPrefab.transform.localScale += new Vector3(temp.x, temp.y);
}
}
void SpawnMultiPlayer2()
{
Instantiate(collectorPrefab);
collectorPrefab.transform.position = new Vector3(5, 12);
collectorPrefab.transform.localScale = new Vector3(2, 2);
if (scaled == true)
{
//store scale of this transform in temporary variable
Vector2 temp = transform.localScale;
//change the values for this saved variable (not actual transform scale)
temp.x = scale;
temp.y = scale;
//assign temp variable back to transform scale
collectorPrefab.transform.localScale = temp;
collectorPrefab.transform.localScale += new Vector3(temp.x, temp.y);
}
}
void SpawnSinglePlayer()
{
Instantiate(collectorPrefab);
collectorPrefab.transform.position = new Vector3(0, 12);
collectorPrefab.transform.localScale = new Vector3(2, 2);
if (scaled == true)
{
//store scale of this transform in temporary variable
Vector2 temp = transform.localScale;
//change the values for this saved variable (not actual transform scale)
temp.x = scale;
temp.y = scale;
//assign temp variable back to transform scale
collectorPrefab.transform.localScale = temp;
collectorPrefab.transform.localScale += new Vector3(temp.x, temp.y);
}
}
void SetSingleplayer()
{
//multiplayer = false;
Invoke("SpawnSinglePlayer", 0);
}
public void SetMultiplayer()
{
CancelInvoke("SetSingleplayer");
Invoke("SpawnMultiPlayer1", 0);
Invoke("SpawnMultiPlayer2", 0);
}
// Use this for initialization
void Start () {
if (multiplayer == false)
{
SetSingleplayer();
}
if (multiplayer == true)
{
SetMultiplayer();
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612103127im_/https://answers.unity.com/themes/thub/images/avi.jpg)