Quantcast
Channel: Questions in topic: "parenting"
Viewing all articles
Browse latest Browse all 302

Trouble with parent objects and colliders

$
0
0
I have a code that lets me move objects by dragging with the mouse, I want to be able to change the position of the root parent but it doesn´t seem to work This script is assigned to a child object in a hierarchy that also has a collider, I have it this way because I need the collider on the root parent for something else Anybody got any ideas on how to properly reference the root parent? if not Is there a way I can use two colliders on the root parent and be able to differentiate them so I can use them in my script? (code below) public class Drag : MonoBehaviour { private bool selected; // Update is called once per frame void Update () { if(selected == true) { Vector2 cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); gameObject.transform.root.position = new Vector2(cursorPos.x, cursorPos.y); } if (Input.GetMouseButtonUp(0)) { selected = false; } } private void OnMouseOver() { if (Input.GetMouseButtonDown(0)) { selected = true; } }

Viewing all articles
Browse latest Browse all 302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>