Пример #1
0
    void Update()
    {
        if (_charge > 0.0f)
        {
            const float MARGIN = 20;

            GUITexture guiTexture = gameObject.guiTexture;
            if (guiTexture != null)
            {
                if (_chargeGuiTexture == null)
                {
                    _chargeGuiTexture = (GUITexture)GUITexture.Instantiate(guiTexture);

                    GUIText[] childArray = _chargeGuiTexture.GetComponentsInChildren <GUIText>();
                    foreach (GUIText child in childArray)
                    {
                        GameObject.Destroy(child);
                    }

                    Vector3 pos = _chargeGuiTexture.transform.position;
                    pos.z = 2.0f;
                    _chargeGuiTexture.transform.position = pos;

                    Color color = _chargeGuiTexture.color;
                    _chargeGuiTexture.color = _chargeTextureColor;

                    Rect pixelInset = _chargeGuiTexture.pixelInset;
                    pixelInset.x                += MARGIN;
                    pixelInset.y                += MARGIN;
                    pixelInset.width            -= (MARGIN * 2);
                    pixelInset.height           -= (MARGIN * 2);
                    _chargeGuiTexture.pixelInset = pixelInset;

                    if (_chargeTexture != null)
                    {
                        _chargeGuiTexture.texture = _chargeTexture;
                    }
                }
                _chargeGuiTexture.enabled = true;

                Rect currentInset = _chargeGuiTexture.pixelInset;
                currentInset.width           = Mathf.Lerp(0.0f, guiTexture.pixelInset.width - (MARGIN * 2), _charge);
                _chargeGuiTexture.pixelInset = currentInset;
            }
        }
        else
        {
            if (_chargeGuiTexture != null)
            {
                _chargeGuiTexture.enabled = false;
            }
        }
    }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        visable     = false;
        female      = (GUITexture.Instantiate(femalePrefab) as GUITexture);
        male        = (GUITexture.Instantiate(malePrefab) as GUITexture);
        femaleColor = female.color;
        maleColor   = male.color;

        femaleColor.a = 0;
        maleColor.a   = 0;
        female.color  = femaleColor;
        male.color    = maleColor;

        female.GetComponent <Collider>().enabled = false;
        male.GetComponent <Collider>().enabled   = false;
    }
Пример #3
0
    // Use this for initialization
    void Start()
    {
        pauseState = 0;

        quit       = (GUIText.Instantiate(quitPrefab) as GUIText);
        background = (GUITexture.Instantiate(backgroundPrefab) as GUITexture);

        quit.GetComponent <Collider>().enabled = false;


        quitColor = quit.color;
        bgColor   = background.color;

        quitColor.a      = 0;
        bgColor.a        = 0;
        quit.color       = quitColor;
        background.color = bgColor;
    }
Пример #4
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {                                                                // only do anything when the button is pressed:
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //Fires a ray according to where mouse is clicked

            //This is the Bullethole guiTexture
            GUITexture.Instantiate(
                bulletFX,
                new Vector3((Input.mousePosition.x - 16) / Screen.width, (Input.mousePosition.y - 18) / Screen.height, 0),
                Quaternion.identity
                );
            //http://forum.unity3d.com/threads/123624-GUITexture-following-mouse-position-on-the-screen

            //If ray hits anything, do this.
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Debug.DrawLine(character.position, hit.point);
            }
        }
    }
Пример #5
0
    void Update()
    {
        //Player can only fire if in firing position
        if (playerHP.canBeHit)
        {
            if (Input.GetMouseButtonDown(0) & ammo != 0)
            {                                                                // only do anything when the button is pressed:
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //Fires a ray according to where mouse is clicked

                //This is the Bullethole guiTexture
                //http://forum.unity3d.com/threads/123624-GUITexture-following-mouse-position-on-the-screen
                GUITexture.Instantiate(
                    bulletFX,
                    new Vector3((Input.mousePosition.x - 16) / Screen.width, (Input.mousePosition.y - 18) / Screen.height, 0),
                    Quaternion.identity
                    );


                if (playerHP.canShootEnemy)
                {
                    ammo -= 1;

                    //If ray hits anything, do this.
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit))
                    {
                        Debug.DrawLine(character.position, hit.point);


                        //Enemy targeting. If the beam hits, gets gameobject it hit.
                        //Compare the tag with enemy types and do damage when hit.
                        target   = hit.collider.gameObject;
                        targetHP = target.GetComponent <EnemyHealth>();

                        if (target.tag == "Enemy1")
                        {
                            targetHP.health -= 100;
                        }

                        if (target.tag == "Enemy2")
                        {
                            target.renderer.material = hitMat;
                            targetHP.health         -= 50;
                        }

                        if (target.tag == "Enemy3")
                        {
                            target.renderer.material = hitMat;
                            targetHP.health         -= 50;
                        }

                        //prevent errors
                        if (target.tag != "Untagged" & target.tag != "Ground")
                        {
                        }
                    }
                }
            }
        }

        else
        {
            //Reload player automatically when not playing
            ammo = 9;
        }
    }