Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        //virtual world
        Vector3    origin    = transform.position + (transform.forward * 0.3f);
        Vector3    direction = transform.forward;
        RaycastHit hit;


        if (Physics.Raycast(origin, direction, out hit))
        {
            Debug.Log("we hit something  " + hit.collider.gameObject.name);
            //Debug.DrawLine(origin, hit.point,Color.red);
            myLine.SetPosition(0, origin);
            myLine.SetPosition(1, hit.point);
            myLine.SetColors(Color.red, Color.red);
            myLine.SetWidth(0.01f, 0.01f);
            if (InputBroker.GetKeyDown(RightWiimote + ":A"))
            {
                hit.collider.gameObject.tag = "Player";
                taglist.Add(hit.collider.gameObject);
            }
            if (InputBroker.GetKeyDown(RightWiimote + ":Up"))
            {
                if (hit.collider.gameObject.tag == "Player")
                {
                    hit.collider.gameObject.layer = 2;
                }
            }
            if (InputBroker.GetKeyDown(RightWiimote + ":Down"))
            {
                if (taglist.Count != 0)
                {
                    foreach (GameObject obj in taglist)
                    {
                        obj.tag   = "Untagged";
                        obj.layer = 0;
                    }
                }
            }
            if (InputBroker.GetKeyPress(RightWiimote + ":B"))                //select
            {
                SelectObjLst.Add(hit.collider.gameObject);

                hit.collider.gameObject.renderer.material.color = Color.red;
            }
            if (InputBroker.GetKeyPress(RightWiimote + ":One"))                 //remove one
            {
                SelectObjLst.Remove(hit.collider.gameObject);
                hit.collider.gameObject.renderer.material.SetColor("_Color", Color.white);
            }

            if (InputBroker.GetKeyPress(RightWiimote + ":Two"))                 //remove all, restart
            {
                if (SelectObjLst.Count != 0)
                {
                    foreach (GameObject obj in SelectObjLst)
                    {
                        obj.renderer.material.SetColor("_Color", Color.white);
                    }
                }
                if (taglist.Count != 0)
                {
                    foreach (GameObject obj in taglist)
                    {
                        obj.tag   = "Untagged";
                        obj.layer = 0;
                    }
                }
                SelectObjLst.Clear();
                taglist.Clear();
            }
        }
        else
        {
            Debug.Log("we did not");
            myLine.SetPosition(0, origin);
            myLine.SetPosition(1, origin);
            myLine.SetColors(Color.red, Color.red);
            myLine.SetWidth(0.01f, 0.01f);
        }

        if (InputBroker.GetKeyDown(LeftWiimote + ":A"))
        {
            MakeRotation();
        }

        if (InputBroker.GetKeyDown(LeftWiimote + ":B"))
        {
            changeColor();
        }
        if (InputBroker.GetKeyDown(LeftWiimote + ":Left"))
        {
            CommonVariables.mappedRotation.y -= RotationSpeed * Time.deltaTime;
        }

        // Right button rotates the virtual world right (heading only)
        if (InputBroker.GetKeyDown(LeftWiimote + ":Right"))
        {
            CommonVariables.mappedRotation.y += RotationSpeed * Time.deltaTime;
        }
    }