// void Update() {
    // if (selected != null && selected.Count > 0){
    //     selected[0].GetComponent<Rigidbody>().velocity = Vector3.zero;
    // }
    // }


    public static void RotateAll(GameObject center)
    {
        if (!center)
        {
            return;
        }
        var camera = GameObject.Find("Main Camera");
        Camera_Controller cameraController = camera.GetComponent <Camera_Controller>();
        GameObject        relativeRotators = GameObject.Find("RelativeRotators");
        Transform         transform        = relativeRotators.GetComponent <Transform>();

        GameObject[] childsG = new GameObject[transform.childCount];
        int          i       = 0;

        foreach (Transform child in transform)
        {
            childsG[i] = child.gameObject;
            i++;
        }
        foreach (var child in childsG)
        {
            RelativeRotatorData relativeRotatorData = child.GetComponent <RelativeRotatorData>();
            if (relativeRotatorData.willRotate)
            {
                var childTransform = child.GetComponent <Transform>();
                childTransform.RotateAround(center.transform.position, Vector3.up, cameraController.speed * cameraController.direction);
            }
        }
    }
    public static void SelectAllInDirection(Vector3 position, Vector3 direction)
    {
        if (selected != null && selected.Count > 0)
        {
            List <GameObject> inDirection = new List <GameObject>();
            //foreach (GameObject possible in selected)
            //{
            //    if (Vector3.Dot((possible.transform.position - position), direction) >= 0)
            //    {
            //        inDirection.Add(possible);
            //    }
            //}
            RaycastHit hit;
            int        mask = LayerMask.GetMask("PushableBlock");
            if (Physics.SphereCast(position, 0.5f, direction, out hit, direction.magnitude, mask))
            {
                inDirection.Add(hit.transform.gameObject);
            }
            Ray ray = new Ray(position, direction);
            if (Physics.Raycast(ray, out hit, 0.5f, mask))
            {
                inDirection.Add(hit.transform.gameObject);
            }

            if (inDirection.Count > 0)
            {
                ReleaseAll();
                selected = inDirection;
                foreach (GameObject child in selected)
                {
                    // need a different glow for selecting
                    child.GetComponent <Animator>().SetBool("Glow", true);
                }
                RelativeRotatorData rrd = selected[selection_index].GetComponent <RelativeRotatorData>();
                rrd.willRotate = true;
                if (selected[selection_index].GetComponent <Rigidbody>())
                {
                    selected[selection_index].GetComponent <Rigidbody>().useGravity = false;
                    // selected[selection_index].GetComponent<Rigidbody>().velocity = Vector3.zero;
                    selected[selection_index].GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
                }
                selected[selection_index].GetComponent <Animator>().SetBool("Selected", true);
            }
        }
    }
Esempio n. 3
0
    public bool selection()
    {
        RelativeRotatorData rrd = rock.GetComponent <RelativeRotatorData>();

        return(rrd.willRotate);
    }