I have a script that will create new GameObjects and will place it where the mouse is placed on the terrain. Now I need to have a check for collision on other already placed GameObjects on the field.
I check different tutorials and documentation and cannot find a way to do this in code.
My code looks like:
objectToPlace = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/Game/3D Models/Buildings/" + objectName + ".fbx", typeof(GameObject)); objectToPlace.SetActive(true); objectToPlace.transform.localScale = new Vector3(1, 1, 1); objectToPlace = Instantiate(objectToPlace); objectToPlace.transform.Rotate(Vector3.right * 90); BoxCollider collider = (BoxCollider)objectToPlace.AddComponent(typeof(BoxCollider)); collider.isTrigger = true;
In the same class as the above code I have OnTriggerEnter function. But that function is not called. How can I link the Collider to that function in Unity 5.6?
I also tried using the Physics.CheckBox for checking if my new create gameObject does not collide to any other object. But without any succes.