the testing script i have creates new empty gameobjects when i hit the middle mouse button.
i want to set the parent of these new gameobjects to be the very same gameobject that the script itself is attached to. i would have thought that something like
"newObject.transform.parent = gameobject "
would work but its not… am i just missing something here?
using UnityEngine;
using System.Collections;
public class clicktesting : MonoBehaviour
{
public GameObject ClickParent;
void Start()
{
ClickParent = gameObject;
}
void Update()
{
if (Input.GetMouseButtonDown(0))
LClick();
if (Input.GetMouseButtonDown(1))
RClick();
if (Input.GetMouseButtonDown(2))
MClick();
}
private static void MClick()
{
Debug.Log("middle click.");
var newObject = new GameObject();
newObject.name = "look i'm a new object";
// here is where the trouble is
//i want to change the parent of the newly created game object to be the game object this script is attached to
//but "this" or "gameobject" arent happy here and i cant access ClickParent either
newObject.transform.parent = gameObject;
}
private static void LClick()
{
Debug.Log("left click.");
}
private static void RClick()
{
Debug.Log("right click.");
}
}