public override bool Update()
 {
     //gm.AddItem(item, Resources.Load<Sprite>(spritepath));
     gm.AddItem(item, spritepath);
     if (destroy)
     {
         GameObject go = GameObject.FindGameObjectWithTag(item);
         //ObjectController npcController = (ObjectController)go.GetComponent (typeof(ObjectController));
         gm.GameInterface.hideppbutton();
         ObjectController.Destroy(go);
     }
     return(true);
 }
Пример #2
0
    void Explode()
    {
        GameObject       cam  = GameObject.FindGameObjectWithTag("MainCamera");
        CameraController camC = null;

        if (cam)
        {
            camC = cam.GetComponent <CameraController>();
        }
        if (camC)
        {
            camC.AddScreenShake(10.0f, 2.0f, 0.5f, true);
        }
        Instantiate(ExplosionPrefab, transform.position, Quaternion.identity);
        GlobalSoundManager.instance.PlayClip(GlobalSounds.GrenadeExplode, SourcePosition.Center, 1);
        ObjectController objCont = this.GetComponent <ObjectController>();

        if (objCont != null)
        {
            objCont.Destroy();
        }
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        _billboard.transform.rotation = Quaternion.Euler(60, -100, 10);
        if (_destroy)
        {
            _destroyTimer        += Time.deltaTime;
            _empLight.fieldOfView = 120.0f * (1.0f - (_destroyTimer / 0.2f));
            if (_destroyTimer > 0.2f)
            {
                ObjectController objCont = this.GetComponent <ObjectController>();
                if (objCont != null)
                {
                    objCont.Destroy();
                }
            }
            return;
        }

        if (_selectingTarget)
        {
            _selectionTimer += Time.deltaTime;
            if (_selectionTimer >= SelectionSwitchDelay)
            {
                _thrusters[_thrusterID].IsHighlighted = false;

                _selectionTimer = 0;
                ++_thrusterID;
                if (_thrusterID > _maxThrusterID)
                {
                    _thrusterID = 0;
                }

                _thrusters[_thrusterID].IsHighlighted = true;
                GlobalSoundManager.instance.PlayClip(GlobalSounds.EmpScrollTarget, SourcePosition.Center, 1);
            }
        }

        if (_attached)
        {
            Vector3 selfPos = transform.position;
            selfPos.y = 0;
            Vector3 playerPos = _enemyPlayer.transform.position;
            playerPos.y = 0;
            float distToPlayer = (_enemyPlayer.transform.position - transform.position).magnitude;

            if (distToPlayer < PickupRadius)
            {
                // eat
                GlobalSoundManager.instance.PlayStopEmp(false);
                GlobalSoundManager.instance.PlayClip(GlobalSounds.EmpDefuse, SourcePosition.Center, 1);
                BoostPlayer();
                return;
            }

            _explosionTimer += Time.deltaTime;

            if (_explosionTimer > ExplosionTime)
            {
                Explode();
            }
        }
        else if (_thrown)
        {
            Vector3 posSelf = transform.position;
            posSelf.y = 0;
            Vector3 posThruster = _targetPos;
            posThruster.y = 0;

            float distFromThruster = (posThruster - posSelf).magnitude;

            if (distFromThruster < 0.1f)
            {
                AttachToThruster();
                return;
            }

            Vector3 dir = (_targetPos - transform.position).normalized;
            transform.position += dir * ThrowingVelocity * Time.deltaTime;
        }

        _mesh.transform.Rotate(new Vector3(0, _explosionTimer * 20.0f, 0));
    }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        if (!GetComponent <PlayerController>().alive&& _activeItem != null)
        {
            ObjectController objCont = _activeItem.GetComponent <ObjectController>();
            if (objCont != null)
            {
                objCont.Destroy();
            }
        }
        _buttonPrompt.transform.position = transform.position + _promptOffset;
        _buttonPrompt.SetActive(_promptTimer > 0);

        if (_promptTimer > 0)
        {
            _promptTimer -= Time.deltaTime;
            if (_promptTimer < 0)
            {
                _promptTimer = 0;
            }
        }

        if (Input.GetAxis(_pickupAxis) > 0 && !_pickupKeyDown)
        {
            _pickupKeyDown = true;
            if (_activeItem != null)
            {
                _activeItem.GetComponent <IItem>().Release();
                _activeItem = null;
            }
            else
            {
                GameObject[] items = GameObject.FindGameObjectsWithTag("Item");
                if (items.Length > 0)
                {
                    int     closestIndex = 0;
                    Vector3 originPos    = GrabOrigin.position;
                    originPos.y = 0;
                    Vector3 itemPos = items[0].transform.position;
                    itemPos.y = 0;
                    float minLen = (originPos - itemPos).sqrMagnitude;
                    for (int i = 1; i < items.Length; i++)
                    {
                        itemPos   = items[i].transform.position;
                        itemPos.y = 0;
                        float currLen = (originPos - itemPos).sqrMagnitude;
                        if (currLen < minLen)
                        {
                            minLen       = currLen;
                            closestIndex = i;
                        }
                    }


                    if (!(minLen <= (GrabDistance * GrabDistance)))
                    {
                        return;
                    }

                    IItem itemComponent = items[closestIndex].GetComponent <IItem>();

                    if (itemComponent != null)
                    {
                        if (itemComponent.Grab(GrabOrigin))
                        {
                            _activeItem = items[closestIndex];
                            ObjectController objCont = items[closestIndex].GetComponent <ObjectController>();
                            if (objCont != null)
                            {
                                objCont.enabled = false;
                            }
                        }
                        else
                        {
                            _activeItem = null;
                        }
                    }
                }
            }
        }
        else if (Input.GetAxis(_pickupAxis) == 0)
        {
            _pickupKeyDown = false;
        }
    }