Hello i have the following problem:
In this hirachy, i want to call a function of the script “ShapeControll” attached to “gameObject2” from the child “child1”.
gameobject1 (instantiated)
-child1(instantiated)
-child2(instantiated)
gameobject2
script TriggerChoose is attached to child1 (and2) so it has to react on a MouseOver or OnMouseEnter event.
script ShapeControll is attached to gameObject2 and has several functions.
here i instantiate the Collider from a prefab which is supposed to become a child of gameobject1 ( c.transform.parent = gameobject1.transform;)
the problem is, that this does not work, if the parent of the instantiated object is Gameobject1, however it does work perfectly when i use (c.transform.parent = transform;) instead.
but this way, the instantiated objects dont behave like the rigidbody attached to gameobject1
using UnityEngine;
using System.Collections;
public class TriggerChoose : MonoBehaviour {
public GameObject controll;
public int shape;
void OnMouseEnter() {
controll.GetComponent<ShapeControll>().switchShape(shape);
}
}
//some functions from the ShapeControll script
using UnityEngine;
using System.Collections;
public class ShapeControll: MonoBehaviour {
public void switchShape(int shape){
Debug.Log("here");
}
void initiateCollider(int j){
Vector3 dposition = gameobject1.transform.position+radialPositions[j] ;
//Vector3 dposition = radialPositions[j] ;
GameObject c = (GameObject) Instantiate (colliderPrefab, dposition, Quaternion.identity);
c.GetComponent<TriggerChoose>().shape = j;
c.GetComponent<TriggerChoose>().controll = this.gameObject;
c.transform.parent = transform;
}
I have the feeling, that the MouseOver or OnMouseEnter functions are not called. Do you have any suggestions?