I'm an experienced developer but new to Unity. I'm using Unity 5.0.1 and working with the CharacterThirdPersonAI scene from the sample pack. I added a button to the scene to instantiate multiple GameObjects instead of just the one from the sample pack. The existing logic uses a PreFab named TargetPicker which has an instance of the GameObject that will be moving assigned by the inspector. TargetPicker also has script PlaceTargetWithMouse which get the mouse click position and sets the GameObject transform.
I added a setter function to PlaceTargetWithMouse to set the GameObject script. I added a button to the UI which has my script AddPlayerToField, a reference TargetPicker assigned by the inspector from the Hierarchy. My intention is to instantiate the player and pass it to the setter function in PlaceTargetWithMouse. I have tried several different ways but cannot get a reference to PlaceTargetWithMouse to call the setter function. PlaceTargetWithMouse has the namespace setting "namespace UnityStandardAssets.SceneUtils". If I try to reference SceneUtils in my script, the compiler complains that it does not exist in UnityStandardAssets. I tried to comment out the namespace setting in PlaceTargetWithMouse but it did not make a difference. I've spent quite a bit of time and don't really know where to go from here. Any help is appreciated. I commented out my attempts below to get the compiler to stop complaining.
using UnityEngine;
using System.Collections;
public class AddPlayerToField : MonoBehaviour {
private int numPlayers = 0;
private GameObject go;
// private SceneUtils.PlaceTargetWithMouse mtp;
public GameObject targetLocator;
public void Start() {
go = (GameObject)Instantiate (targetLocator);
//mtp = go.GetComponent();
}
public void AddGamePlayer(GameObject player) {
numPlayers += 1;
GameObject player1 = (GameObject)Instantiate(player, new Vector3(numPlayers * 2.0F, 0, 0), Quaternion.identity);
//((PlaceTargetWithMouse)targetLocator.GetComponent(typeof(PlaceTargetWithMouse))).SetTargetPlayer(player1);
//mtp.SetTargetPlayer(player1);
}
}
↧