示例#1
0
    // Update is called once per frame
    void Update()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;

        if (Physics.Raycast(ray, out hitInfo, 500) == true)
        {
            // update crosshair
            //Vector3 crosshairPos = new Vector3(hitInfo.point.x, hitInfo.point.y, crosshair.transform.position.z);
            // crosshair.transform.position = crosshairPos;

            Vector3 newPos = new Vector3(hitInfo.point.x, hitInfo.point.y, hitInfo.transform.position.z);
            output.text = hitInfo.transform.gameObject.name + "- " + newPos.x + " ," + newPos.y;
            // check for hits
            if (Input.GetAxis("Fire1") > 0.0f)
            {
                if (hitInfo.transform.gameObject.tag == "ExplodingBox")
                {
                    particleController.PlayExplosion(hitInfo.transform.position);
                    Destroy(hitInfo.transform.gameObject);
                    //hitInfo.transform.position = newPos;
                }
                if (hitInfo.transform.gameObject.tag == "Balloon")
                {
                    particleController.PlayBalloonPop(hitInfo.transform.position);
                    hitInfo.transform.gameObject.GetComponent <Cloth>().enabled = true;
                }
            }
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (mainCamera == null)
        {
            Debug.LogError("RayCaster script was unable to get a camera from Camera.main");
            return;
        }

        Ray        ray = mainCamera.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;

        if (Physics.Raycast(ray, out hitInfo, 500) == true)
        {
            // update crosshair
            Vector3 newPos = new Vector3(hitInfo.point.x, hitInfo.point.y, hitInfo.transform.position.z);
            output.text = hitInfo.transform.gameObject.name + "- " + newPos.x + " ," + newPos.y;
            // check for hits
            if (Input.GetAxis("Fire1") > 0.0f)
            {
                // hit box
                if (hitInfo.transform.gameObject.tag == "ExplodingBox")
                {
                    particleController.PlayExplosion(hitInfo.transform.position);
                    // destroy box, could just disable/hide box instead for reuse later
                    Destroy(hitInfo.transform.gameObject);
                }
                // hit balloon
                if (hitInfo.transform.gameObject.tag == "Balloon")
                {
                    particleController.PlayBalloonPop(hitInfo.transform.position);
                    particleController.PlayWaterDrop(hitInfo.transform.position);
                    // enable cloth on balloon so it droops
                    hitInfo.transform.gameObject.GetComponent <Cloth>().enabled = true;
                }
            }
        }
    }