- Home /
OnTriggerEnter and UI Collisions.
Hey folks, currently having a bit of bother trying to get this to work. I am dealing with moving UI elements that are clamped to a gameobject, which is fine but they do overlap and I was thinking that I could implement something that when they collide, add 2/3 to their current y position. I have tried OnTriggerEnter and tested to see if its being picked up that the UI are colliding which they are, just unsure of the next step. Getting the UI to move up. I have tried a few things but I cant get them to work, I get the Only assignment, call, increment, decrement, and new object expressions can be used as a statement error.
Example of what I am looking at.
Example of the code; if that helps. Although I have a animation and movement being triggered on other scripts that is linked to this, but this is the one that looks at their positions.
if (gameObject.tag == "WheelParts")
{
//get the gameObjects name that canvas is attached to
canvasName.text = gameObject.name;
newPos = mainCam.WorldToScreenPoint(this.transform.position);
//set the position of the UI
newPos.x = transform.position.x + 3.5f;
newPos.y = transform.position.y + 3f;
newPos.z = transform.position.z + 7f;
//set the canvas position
canvasName.transform.position = newPos;
//canvas rotation
canvasName.transform.rotation = Quaternion.Euler(0, 0, 0);
}
Would appreciate any help or pointers. Thanks.
Your answer
Follow this Question
Related Questions
Collison detection not working? 1 Answer
SetActive messes up everything? 1 Answer
OnTriggerEnter does not work 1 Answer
How do you make a method that gets called when a button gets highlighted using the arrow keys? 0 Answers
Destroy by Contact (OnTriggerEntry) - destroying more then i want. 0 Answers