Esempio n. 1
0
    private float startTime  = 0.0f;       //time that the shell instance was created in the world

    void Start()
    {
        //set up external script references
        WeaponBehavior WeaponBehaviorComponent = gunObj.GetComponent <WeaponBehavior>();

        myTransform        = transform; //manually set transform for efficiency
        playerObjTransform = playerObj.transform;
        //initialize shell rotation amounts
        shellRotateUp   = WeaponBehaviorComponent.shellRotateUp / (Time.fixedDeltaTime * 100.0f);
        shellRotateSide = WeaponBehaviorComponent.shellRotateSide / (Time.fixedDeltaTime * 100.0f);
        shellDuration   = WeaponBehaviorComponent.shellDuration;
        //track the time that the shell was ejected
        startTime = Time.time;
        //set initial parent to gun object to inherit player velocity
        myTransform.parent           = gunObj.transform;
        lerpShell.parent             = gunObj.transform;
        shellRemovalTime             = Time.time + shellDuration; //time that shell will be removed
        rigidbody.maxAngularVelocity = 100;                       //allow shells to spin faster than default
        //determine if shell rotates clockwise or counter-clockwise at random
        if (Random.value < 0.5f)
        {
            shellRotateUp *= -1;
        }
        tempPos            = myTransform.position;
        lerpShell.position = tempPos;
    }
Esempio n. 2
0
    // Use this for initialization
    void Start()
    {
        this.player = GameObject.FindGameObjectWithTag("Player");
        var weaponsComponents = GetComponentsInChildren(typeof(WeaponBehavior));

        WeaponBehavior[] w = new WeaponBehavior[weaponsComponents.Length];
        for (int i = 0; i < weaponsComponents.Length; i++)
        {
            w[i] = (WeaponBehavior)weaponsComponents[i];
            if (shipType == ShipType.Player)
            {
                //make the player's ship have ui elements
                var prefab     = Instantiate(weaponInfoPrefab, MainUICanvas.transform);
                var prefabRect = prefab.GetComponent <RectTransform>().rect;
                prefab.transform.position += new Vector3(0, -i * prefabRect.height, 0);

                w[i].TieToUI(prefab);
            }
        }
        weapons = new List <WeaponBehavior>(w);
        //TODO uncomment code below once ShipParts are implemented

        /*var bodyComponents = GetComponentsInChildren<ShipParts>();
         * foreach(ShipParts c in bodyComponents){
         *  fullHealth += c.componentHealth;
         * }
         *
         */
        fullHealth    += componentHealth;
        _currentHealth = fullHealth;

        this._resources = resources;
    }
    IEnumerator Equipping(WeaponBehavior weapon)
    {
        if (equipped != null)
        {
            float horizontal = Input.GetAxis("Horizontal");
            float vertical   = Input.GetAxis("Vertical");
            Throw(new Vector2(horizontal, vertical));
        }
        equipped = weapon;
        if (equipped.transform.parent != null)
        {
            equipped.transform.parent.GetComponent <MovingPlatform>().otherObjs.Remove(equipped.transform);
        }
        equipped.thrown                  = false;
        equipped.transform.parent        = weaponSlot;
        equipped.transform.localPosition = Vector3.zero;
        equipped.pb   = this;
        equipped.held = true;

        float delay = 1f;
        float count = 0;

        equipping = true;
        while (count < delay)
        {
            count += Time.deltaTime;
            yield return(null);
        }
        equipping = false;
    }
Esempio n. 4
0
    void UpdateWeapon()
    {
        if (m_input.fire)
        {
            if (KartState.UsingWeapon)
            {
                KartState.UsingWeapon.Activate();
            }
            else if (WeaponPrefab.Count > 0)
            {
                GameObject weaponGo = WeaponPrefab[0];
                WeaponPrefab.RemoveAt(0);
                weaponGo = Instantiate(weaponGo);
                WeaponBehavior wb = weaponGo.GetComponent <WeaponBehavior>();
                wb.Owner = this;
                wb.Initialize(this);

                if (WeaponPrefab.Count == 0)
                {
                    UIPlayerManager.HideWeapon();
                    KartState.IsArmed = false;
                }
                else
                {
                    UIPlayerManager.DecrementWeaponText();
                }
            }
        }
    }
    void SetBackgroundColor(WeaponBehavior weaponBehavior)
    {
        Color rarityColor = weaponBehavior.weaponRarity.main.startColor.color;

        rarityColor           = new Color(rarityColor.r, rarityColor.g, rarityColor.b, 0.7f);
        backgroundColor.color = rarityColor;
    }
Esempio n. 6
0
    void OnTriggerEnter(Collider other)
    {
        PlayerController taker;

        if (other.tag == "Kart")       // si c'est un kart
        {
            taker = other.GetComponent <PlayerController>();
        }
        else if (other.tag == "Weapon")        // si c'est une bombe ou autre
        {
            WeaponBehavior es = other.GetComponent <WeaponBehavior>();
            taker = es.Owner;
        }
        else
        {
            return;
        }

        GetComponent <AudioSource>().Play();
        m_selfCollider.enabled = false;
        int n = Random.Range(4, 8);

        taker.ChangeApples(n);
        Main.statistics.nbAppleBox += 1;
        StartCoroutine(Take());
    }
Esempio n. 7
0
    IEnumerator AimLine()
    {
        Transform      weapon         = transform.Find("Equipment").Find("WeaponSlot").GetChild(activeWeapon).transform.GetChild(0);
        WeaponBehavior weaponBehavior = weapon.GetComponent <WeaponBehavior>();

        float      aimLineOpacity;
        GameObject aimLine = Instantiate(weaponBehavior.aimLine, transform.position, transform.rotation);

        aimLine.transform.parent = rb.transform;
        Color color = aimLine.transform.GetChild(0).GetComponent <SpriteRenderer>().color;

        aimLineOpacity = 0;
        while (aimLineOn == true)
        {
            aimLineOpacity = Mathf.Lerp(aimLineOpacity, 1, 2f * Time.deltaTime);
            aimLine.transform.GetChild(0).GetComponent <SpriteRenderer>().color = new Color(color.r, color.g, color.b, aimLineOpacity);
            yield return(new WaitForEndOfFrame());
        }

        while (aimLineOpacity > .01f)
        {
            aimLineOpacity = Mathf.Lerp(aimLineOpacity, 0, 10f * Time.deltaTime);
            aimLine.transform.GetChild(0).GetComponent <SpriteRenderer>().color = new Color(color.r, color.g, color.b, aimLineOpacity);
            yield return(new WaitForEndOfFrame());
        }

        Destroy(aimLine);
    }
Esempio n. 8
0
        public void swap_slots()
        {
            if (slot2 != null)
            {
                slot2.SetActive(true);
            }

            GameObject item = slot1;

            slot1 = slot2;
            slot2 = item;

            if (slot2 != null)
            {
                slot2.SetActive(false);
            }

            if (slot1 == null)
            {
                holding_weapon  = false;
                weapon_behavior = null;
            }
            else
            {
                holding_weapon  = true;
                weapon_behavior = slot1.GetComponent <WeaponBehavior>();
            }


            Debug.Log("Swap");
        }
Esempio n. 9
0
    private bool audioPaused;    // used to pause and resume reloading sound based on timescale/game pausing state

    void Start()
    {
        WeaponBehavior BackupWeaponBehaviorComponent = weaponOrder[backupWeapon].GetComponent <WeaponBehavior>();

        myTransform      = transform;   //define transforms for efficiency
        mainCamTransform = Camera.main.transform;

        //Create Instance of GUIText to display ammo amount on hud. This will be accessed and updated by WeaponBehavior script.
        ammoGuiObjInstance = Instantiate(ammoGuiObj, Vector3.zero, myTransform.rotation) as GameObject;

        //set the weapon order number in the WeaponBehavior scripts
        for (int i = 0; i < weaponOrder.Length; i++)
        {
            weaponOrder[i].GetComponent <WeaponBehavior>().weaponNumber = i;
        }

        //Select first weapon, if firstWeapon is not in inventory, player will spawn unarmed.
        if (weaponOrder[firstWeapon].GetComponent <WeaponBehavior>().haveWeapon)
        {
            StartCoroutine(SelectWeapon(firstWeapon));
        }
        else
        {
            StartCoroutine(SelectWeapon(0));
        }

        //set droppable value for backup weapon to false here if it was set to true in inspector
        //to prevent multiple instances of backup weapon from being dropped and not selecting next weapon
        BackupWeaponBehaviorComponent.droppable = false;
        //set addsToTotalWeaps value for backup weapon to false here if it was set to true in inspector
        //to prevent picking up a backup weapon from swapping current weapon
        BackupWeaponBehaviorComponent.addsToTotalWeaps = false;

        UpdateTotalWeapons();
    }
Esempio n. 10
0
 public void on_raycast_collision(RaycastHit hit)
 {
     if (hit.collider.tag == "Weapon" && weapon_slots.can_pickup())
     {
         weapon_slots.pick_up(hit.collider.gameObject);
         weapon_script = weapon_slots.get_script();
     }
     else if (hit.collider.tag == "Backpack" && backpack_slot.can_pickup())
     {
         backpack_slot.pick_up(hit.collider.gameObject);
     }
     else if (hit.collider.tag == "Ammo")
     {
         AmmoBox ammobox = hit.collider.gameObject.GetComponent <AmmoBox>();
         ammobox.on_pickup();
         player_inventory.pick_up(ammobox);         //w inventory musze wiedzieci ile mam ammo i usuwac puste pudelka (to juz chyba zrobione)
     }
     else if (hit.collider.tag == "Item")
     {
         Debug.Log("item hit");
         Item item = hit.collider.gameObject.GetComponent <Item>();
         item.on_pickup();
         player_inventory.pick_up(item);
     }
 }
Esempio n. 11
0
 public void SetBehavior(WeaponBehavior behavior)
 {
     Icon.sprite = behavior.Icon;
     EndsTurnIndicator.SetActive(behavior.EndTurn);
     Name.text        = behavior.ActionID;
     Description.text = behavior.Description.Replace("<br>", "\n");
 }
Esempio n. 12
0
    public void ShowWeapon(WeaponBehavior weapon)
    {
        Reset();

        if (weapon.damage > 0)
        {
            NewValueDisplay(weapon.damage.ToString("F1"), GameManager.instance.library.damageIcon);
        }
        if (weapon.speed > 0)
        {
            NewValueDisplay(weapon.speed.ToString("F1"), GameManager.instance.library.speedIcon);
        }
        if (weapon.range > 0)
        {
            NewValueDisplay(weapon.range.ToString("F1"), GameManager.instance.library.rangeIcon);
        }

        self.sizeDelta = new Vector2(self.sizeDelta.x, requiredHeight + shiftValue);

        self.gameObject.SetActive(true);

        if (improveInterface == null)
        {
            improveInterface = Instantiate(improvePrefab, transform.position, Quaternion.identity, transform)
                               .GetComponent <ImproveInterface>();
        }

        improveInterface.weapon        = weapon;
        improveInterface.self.position = new Vector2
                                         (
            self.position.x,
            self.position.y - self.sizeDelta.y * 0.5f - improveInterface.self.sizeDelta.y * 0.5f - GameManager.instance.interfaceManager.boxesSpacing
                                         );
        improveInterface.ChangePrice(weapon.tower.param.price * weapon.tower.param.levelMultiplier[weapon.tower.level]);
    }
Esempio n. 13
0
    public void LoadTower(TowerParam _param)
    {
        // Applying param
        param = _param;

        gameObject.name = "Tower_" + param.title;

        // Visuals
        visual = Instantiate(param.model, transform.position, Quaternion.identity, transform).GetComponent <TowerVisualsBehavior>();
        if (visual != null)
        {
            visual.tower = this;
        }

        // Shooting behavior
        if (weapon == null)
        {
            weapon = GetComponent <WeaponBehavior>();
        }
        if (weapon == null)
        {
            weapon = gameObject.AddComponent <WeaponBehavior>();
        }
        weapon.tower = this;

        weapon.Load(
            param.damage * param.levelMultiplier[level],
            param.speed * param.levelMultiplier[level],
            param.range * param.levelMultiplier[level]
            );
    }
Esempio n. 14
0
 public void Start()
 {
     weaponObj = transform.gameObject;
     PlayerWeaponsComponent  = weaponObj.GetComponentInChildren <PlayerWeapons>();
     WeaponBehaviorComponent = PlayerWeaponsComponent.CurrentWeaponBehaviorComponent;
     FPSWalkerComponent      = Camera.main.transform.GetComponent <CameraControl>().playerObj.GetComponent <FPSRigidBodyWalker>();
 }
Esempio n. 15
0
    void Update() {
        health.value = player.stat.playerHealth * 0.01f;

        foreach (GameObject weap in GameObject.FindGameObjectsWithTag("Weapon")) {
            if(weap.activeInHierarchy)
                weapon = weap.GetComponent<WeaponBehavior>();
        }



        ammo.maxValue = Utilities.GetWeaponData(weapon.weaponID).ClipSize;
        ammo.value = weapon.clipSize;

        divinity.maxValue = Player.Instance.stat.playerDivinity;
        divinity.value = Player.Instance.currentDivinity; 
        
        //GUI.TextField(new Rect(Screen.width*0.03f, Screen.height - 50, 50f, 40),"Yuima");

        //GUI.TextField(new Rect(Screen.width * 0.09f, Screen.height - 50, 150f, 20), "Divinity: " + GameObject.FindGameObjectWithTag("Player").GetComponent<Player>().stat.playerDivinity );
        //GUI.TextField(new Rect(Screen.width * 0.09f, Screen.height - 30, 150f, 20), "Health: " + GameObject.FindGameObjectWithTag("Player").GetComponent<Player>().stat.playerHealth);


        //GUI.DrawTexture(new Rect(Screen.width/2, Screen.height - 300, Screen.width/2, Screen.height/2), health);


        //GUI.TextField(new Rect(Screen.width * 0.03f, Screen.height - 200, 50f, 150), "\n g \n o \n d \n\n t \n y \n p \n e");
        // Temporary Crosshair
        if (Input.GetKey(KeyCode.Escape)) {
            Cursor.visible = !Cursor.visible;
        }
        
    }
Esempio n. 16
0
    public override void CauseEventEffect()
    {
        Debug.Log("Doing tripple shot Attack event");
        // Cause the event effect logically and visually
        for (int i = 0; i < 3; i++)
        {
            Debug.Log("Doing single shot Attack event");

            GameObject weapon = GameObject.Instantiate(item.weaponSOAsset.weaponPrefab, player.transform.position + new Vector3(0, 0.5f, 0), Quaternion.identity) as GameObject;

            WeaponBehavior weaponBehavior = weapon.GetComponent <WeaponBehavior>();
            weaponBehavior.SetSOAsset(item);

            Vector3 p      = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector3 result = (new Vector3(p.x, p.y, 0.0f) - new Vector3(player.transform.position.x, player.transform.position.y, 0.0f)).normalized;

            if (i == 0)
            {
                weaponBehavior.SetDetails(5.0f, Quaternion.Euler(0, 0, -90f) * result);
            }
            else if (i == 2)
            {
                weaponBehavior.SetDetails(5.0f, Quaternion.Euler(0, 0, 90f) * result);
            }
            else
            {
                weaponBehavior.SetDetails(5.0f, result);
            }
        }
    }
Esempio n. 17
0
 public void Equip(WeaponBehavior weapon)
 {
     if (!equipping)
     {
         StartCoroutine(Equipping(weapon));
     }
 }
Esempio n. 18
0
 public void drop_weapon()
 {
     if (weapon_slots.can_drop())
     {
         weapon_slots.drop_weapon();
         weapon_script = null;
     }
 }
Esempio n. 19
0
    void FireWeapon()
    {
        WeaponBehavior weapon = transform.Find("Equipment").Find("WeaponSlot").GetChild(activeWeapon).GetChild(0).GetComponent <WeaponBehavior>();

        stats.energy            -= weapon.EnergyDrainAmount;
        stats.lastEnergyUsedTime = Time.time;
        weapon.FireWeapon(transform, playerVelocity);
    }
Esempio n. 20
0
    public WeaponBehavior ShootWeapon(Vector3 SpawnPosition, LookingDirection direction, PlayerController owner)
    {
        WeaponBehavior instantiated = Instantiate(weaponPrefab, SpawnPosition, Quaternion.identity);

        instantiated.damage = weaponDamage;
        instantiated.Init(initialVelocity, direction, owner);
        return(instantiated);
    }
Esempio n. 21
0
    void DeactivateSword()
    {
        WeaponBehavior weapon = transform.Find("Equipment").Find("WeaponSlot").GetChild(activeWeapon).GetChild(0).GetComponent <WeaponBehavior>();

        if (weapon.GetComponent <Collider>())
        {
            weapon.GetComponent <Collider>().enabled = false;
        }
    }
Esempio n. 22
0
 public void SetWeapon(WeaponBehavior weapon)
 {
     if (_availableWeapons.ContainsKey(weapon.weaponStats.weaponID))
     {
         _availableWeapons[weapon.weaponStats.weaponID].SetHolder(null);
     }
     weapon.SetHolder((weaponHolder != null) ? weaponHolder : gameObject);
     _availableWeapons[weapon.weaponStats.weaponID] = weapon;
     selected = weapon;
 }
Esempio n. 23
0
 public void Throw(Vector2 direction)
 {
     equipped.transform.parent = null;
     if (direction.x == 0 && direction.y == 0)
     {
         direction.x = Mathf.FloorToInt(transform.localScale.x);
     }
     equipped.ThrowDirection(direction);
     equipped = null;
 }
    // Use this for initialization
    void Start()
    {
        rb2d   = GetComponent <Rigidbody2D>();
        Script = GetComponent <PlayerManager>();

        if (heldWeapon)
        {
            heldWeaponScript = heldWeapon.GetComponent <WeaponBehavior>();
        }
    }
Esempio n. 25
0
/*
 *      void on_drag_collision(RaycastHit hit)
 *      {
 *              if(hit.collider.tag == "Drag"){
 *                      slot1 = hit.collider.gameObject;
 *                      holding = true;
 *              }
 *      }
 */
        public void pick_up(GameObject item)
        {
            item.GetComponent <Rigidbody>().isKinematic = true;
            weapon_behavior = item.GetComponent <WeaponBehavior>();
            item.transform.SetParent(main_camera_transform);
            item.transform.SetPositionAndRotation(hand_position.position, new Quaternion(0, 0, 0, 0));
            item.transform.localEulerAngles           = new Vector3(-90, 180, 0);
            item.GetComponent <BoxCollider>().enabled = false;
            slot1          = item;
            holding_weapon = true;
        }
Esempio n. 26
0
    // Use this for initialization
    void Start()
    {
        rigidbod           = gameObject.GetComponent(typeof(Rigidbody)) as Rigidbody; //Calls for the GO's Rigidbody
        obj                = GetComponent <Transform>();                              //Calls for the GO's transform component
        lastPos            = obj.position;                                            //Sets the LastPos var
        originalSpeed      = MoveSpeed;                                               //Sets the OriginalSpeed var
        originalRestTime   = restTime;                                                //Sets originalRestTime var
        originalStamina    = Stamina;                                                 //Sets originalStamina var
        originalSafetyTime = safetyTime;

        weaponBehavior = weapon.GetComponent <WeaponBehavior>();             //References other script to monitor weapon speed
    }
Esempio n. 27
0
File: Controls.cs Progetto: Lrss/P3
	// Use this for initialization
	void Start () {
        initialPosition = transform.position;
        if (gameObject.name == "Player1Cursor") //Checks the name of the player the cursor belongs to
        {
            inputPrefix = "1";
            playerObject = GameObject.Find("Player1");
        }
        GameManager = GameObject.FindWithTag("GameController");
        OpenCVData = playerObject.GetComponentInChildren<Listener>();
        speed = 10f;
        weaponBehaviorScript = playerObject.GetComponentInChildren<WeaponBehavior>();
	}
    public void AddWeapon(GameObject prefabWeapon)
    {
        if (heldWeapon)
        {
            Destroy(heldWeapon);
        }
        GameObject weapon = (GameObject)Instantiate(prefabWeapon, transform.position, transform.rotation);

        heldWeapon       = weapon;
        heldWeaponScript = heldWeapon.GetComponent <WeaponBehavior>();
        heldWeapon.transform.SetParent(this.transform);
    }
Esempio n. 29
0
 void updateWeaponIcon(WeaponBehavior wb)
 {
     if (wb != null)
     {
         Debug.Log("Change Icon");
         weaponIcon.sprite = wb.weaponStats.icon;
     }
     else
     {
         weaponIcon.sprite = defaultIcon;
     }
 }
    private void OnTriggerEnter(Collider other)
    {
        WeaponBehavior theirWeapon = other.GetComponentInParent <WeaponBehavior>();

        if (theirWeapon != null)
        {
            weapons.Add(theirWeapon);
            theirWeapon.transform.position = transform.position;
            theirWeapon.transform.rotation = transform.rotation;
            theirWeapon.transform.SetParent(transform);
            ChangeWeaponIndex(weapons.Count - 1);
        }
    }
Esempio n. 31
0
File: Controls.cs Progetto: Lrss/P3
 // Use this for initialization
 void Start()
 {
     initialPosition = transform.position;
     if (gameObject.name == "Player1Cursor") //Checks the name of the player the cursor belongs to
     {
         inputPrefix  = "1";
         playerObject = GameObject.Find("Player1");
     }
     GameManager          = GameObject.FindWithTag("GameController");
     OpenCVData           = playerObject.GetComponentInChildren <Listener>();
     speed                = 10f;
     weaponBehaviorScript = playerObject.GetComponentInChildren <WeaponBehavior>();
 }
Esempio n. 32
0
    public void OnPointerEnter(PointerEventData eventData)
    {
        if (equippedWeapon && equippedWeapon.GetComponent <WeaponBehavior>())
        {
            WeaponBehavior weaponBehavior = equippedWeapon.GetComponent <WeaponBehavior>();

            weaponStats.GetComponent <Canvas>().enabled = true;
            weaponStats.GetComponent <WeaponStatsInventory>().GetGunStat(weaponBehavior);
            Vector3 pointerPosition = eventData.position;
            //pointerPosition.y += 120;
            weaponStats.transform.position = pointerPosition;
        }
    }
Esempio n. 33
0
 public void setWeapon(WeaponBehavior wp)
 {
     this.weaponBehavior=wp;
 }
Esempio n. 34
0
 public King(WeaponBehavior weapon)
 {
     setWeapon(weapon);
 }