void SpawnPlayer (Transform ship)
{
Vector3 centPos = new Vector3(0,0,0);
Object playerP = Network.Instantiate(Player, centPos, centPos, mainCamGroup);
ship.parent = playerP.transform;
}
Ship is another instantiated object.
I need to obtain the transform from an initiated clone, however the type of instantiate is ‘Object’ which has no Transform type.
How do I do what i’m trying to achieve?
Thanks in advance, and please ask if you have questions! Ill be monitoring constantly for now.
EDIT----------
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour {
/// <summary>
/// This script is attached to the 'Game Manager' and
/// allows player to spawn, after selecting the pre game options
/// </summary>
//Variables-----------------------------------------------------------------
private bool justConnectedToServer = false;
//Used to determine which civ player is on.
public bool american = false;
public bool british = false;
private int mainCamGroup = 0;
//Used to defined join civ window
private Rect joinCivRect;
private string joinCivWindowTitle = "Select Your Mother Civilation";
private int joinCivWindowWidth = 330;
private int joinCivWindowHeight = 100;
private int joinCivLeftIndent;
private int joinCivTopIndent;
private int buttonHeight = 40;
public GameObject Player;
public GameObject amCivMothShip;
public GameObject britCivMothShip;
private GameObject[] eastSpawnPoints;
private int amCivGroup = 1;
private int britCivGroup = 2;
//End of Variables----------------------------------------------------------
void OnConnectedToServer ()
{
justConnectedToServer = true;
}
void PickMotherCivWindow (int windowID)
{
//If the player clicks join American button, they're assigned to American and are spawned.
if(GUILayout.Button("American", GUILayout.Height(buttonHeight)))
{
american = true;
justConnectedToServer = false;
SpawnAmericanMothShip();
}
//If the player clicks join british button, they're assigned to british and are spawned.
if(GUILayout.Button("British", GUILayout.Height(buttonHeight)))
{
british = true;
justConnectedToServer = false;
SpawnBritishMothShip ();
}
}
void OnGUI ()
{
if(justConnectedToServer == true)
{
joinCivLeftIndent = Screen.width / 2 - joinCivWindowWidth / 2;
joinCivTopIndent = Screen.height / 2 - joinCivWindowHeight / 2;
joinCivRect = new Rect(joinCivLeftIndent, joinCivTopIndent,
joinCivWindowWidth, joinCivWindowHeight);
joinCivRect = GUILayout.Window(0, joinCivRect, PickMotherCivWindow, joinCivWindowTitle);
}
}
void SpawnAmericanMothShip ()
{
//Find all spawn points, and establish a reference in an array.
eastSpawnPoints = GameObject.FindGameObjectsWithTag("SpawnEast");
//Below will randomly select a spawn point
GameObject eastSpawnPoint = eastSpawnPoints[Random.Range(0, eastSpawnPoints.Length)];
//Instantiate player at random spawn
GameObject ship = (GameObject)Network.Instantiate(amCivMothShip, eastSpawnPoint.transform.position,
eastSpawnPoint.transform.rotation, amCivGroup);
SpawnPlayer((GameObject)ship);
}
void SpawnBritishMothShip ()
{
//Find allspawn points, and establish a reference in an array.
eastSpawnPoints = GameObject.FindGameObjectsWithTag("SpawnEast");
//Below will randomly select a spawn point
GameObject eastSpawnPoint = eastSpawnPoints[Random.Range(0, eastSpawnPoints.Length)];
//Instantiate ship at random spawn
GameObject ship = (GameObject)Network.Instantiate(britCivMothShip, eastSpawnPoint.transform.position,
eastSpawnPoint.transform.rotation, britCivGroup);
SpawnPlayer((GameObject)ship);
}
void SpawnPlayer (GameObject ship)
{
Vector3 centPos = new Vector3(0,0,0);
GameObject playerP = (GameObject)Network.Instantiate(Player, centPos, Quaternion.Euler(0,0,0), mainCamGroup);
ship.transform.parent = playerP.transform;
}
}
Im sorry for the long script, but since i’m probably making a stupid mistake, id rather not edit out the useless stuff.
As a side note, i double checked the assignments to the GameObjects AmCivMothShip, BritCivMothShip, and player.
As a side side note, ‘civ’ is short for civilization, ‘moth’ is short for mother. Am and Brit are american and british respectively(obviously).