transform.position problem

Hi,

I have an empty game object with the following script attached:

using UnityEngine;
using System.Collections;

public class GameMaster : MonoBehaviour {
	
	public GameObject playerCharacter;
	
	private GameObject _pc;
	
	private Vector3 _playerSpawnPos;

	void Start () {
		
		_playerSpawnPos = new Vector3(20.0f, 4.0f, 20.0f);
		
		//_pc = Instantiate( playerCharacter, _playerSpawnPos, Quaternion.identity ) as GameObject;
		_pc = Instantiate( playerCharacter, Vector3.zero, Quaternion.identity ) as GameObject;
		
		_pc.name = "wtf";	
		
		_pc.transform.position = _playerSpawnPos;
	}
}

I have a prefab based on the Camera Relative Controls controller. This prefab becomes my “playerCharacter” Game Object. When I transform the position the joysticks show up at (-20, -4, 0). So they aren’t showing up in the camera. The capsule and the camera transform ok, just not the joysticks. What am I missing?

Thanks for any help!!

Cheers!

Jim

DaveA,

You were correct in that I shouldn’t be moving the joysticks. Thanks for that pointer!

So the corrected code is:

using UnityEngine;
using System.Collections;
 
public class GameMaster : MonoBehaviour {
 
    public GameObject playerCharacter;
 
    private GameObject _pc;
 
    private Vector3 _playerSpawnPos;
 
    void Start () {
 
       _playerSpawnPos = new Vector3(20.0f, 4.0f, 20.0f);
 
       _pc = Instantiate( playerCharacter, Vector3.zero, Quaternion.identity ) as GameObject;
 
       _pc.name = "wtf"; 
 
       _pc.transform.Find("Camera Relative Controls").position = _playerSpawnPos;
    }
}

So I basically find the child that holds the player character and the camera (this child is at the same level as the Joysticks), and transform the position of that child. Voila!

Again, thanks for the pointer DaveA!