Esempio n. 1
0
    /*###########
    #   SPAWN   #
    ###########*/

    public void spawnPlayer(string weapon, GameObject spawnPlace, string team)
    {
        GameObject player = PhotonNetwork.Instantiate("soldierPrefab", spawnPlace.transform.position, Quaternion.identity, 0);

        Debug.Log(player);

        //we set the soldier a child of the playerCreator and we set it alive
        player.transform.parent = transform;

        //We select the weapon slot in the right hand
        GameObject weapSlot = player.gameObject.transform.Find("Armature/Dos/Haut_Dos/Epaule_D/Bras_D/Avant_Bras_D/Main_D/Paume_D/Majeur_1_D/weaponSlot").gameObject;

        Debug.Log(weapSlot);

        //We spawn the weapon
        GameObject weaponSelec = PhotonNetwork.Instantiate(weapon, weapSlot.transform.position, Quaternion.identity, 0);


        shotScript shootingScript = weaponSelec.GetComponent <shotScript>();

        weaponSelec.transform.parent = weapSlot.transform;

        playerNetwork playerNet = player.GetComponent <playerNetwork>();

        //playerNet.enabled = true;
        playerNet.playerTeam = team;
        Debug.Log("Spawned player on team " + team);


        //GameObject soldier = player.gameObject.transform.Find("Soldier").gameObject;
    }
Esempio n. 2
0
    //shoot from an other script

    //create a shoot if possible
    public void Attack(int team)
    {
        if (CanAttack || !CanAttack)
        {
            shootCooldown = shootingRate;

            //create an object (from prefabs)
            var shotTransform = Instantiate(shotPrefab) as Transform;

            // Position
            shotTransform.position = transform.position;

            // properties of the script
            shotScript shot = shotTransform.gameObject.GetComponent <shotScript>();
            if (shot != null)
            {
                shot.team = team;
            }

            //direction of the motion
            moveObjectScript move = shotTransform.gameObject.GetComponent <moveObjectScript>();
            if (move != null)
            {
                move.direction = this.transform.right; // ici la droite sera le devant de notre objet
            }
        }
    }
    // When the object is loaded and starts running
    void Awake()
    {
        Transform playerCam = transform.Find("Camera");

        /*-------------- WE SET THE CUSTOM FOV ON THE CAMERA -----------------*/
        Camera playerCamera = playerCam.GetComponent <Camera>();

        FOV = PlayerPrefs.GetInt("playerFOV");
        if (FOV != null)
        {
            playerCamera.fieldOfView = FOV;
        }
        /*-------------------------------------------------------------------*/

        Transform bras_D   = gameObject.transform.Find("Armature/Dos/Haut_Dos/Epaule_D/Bras_D");
        armAim    armAim_D = bras_D.GetComponent <armAim>();

        Transform bras_G   = gameObject.transform.Find("Armature/Dos/Haut_Dos/Epaule_G/Bras_G");
        armAim    armAim_G = bras_G.GetComponent <armAim>();

        MouseLook mouseCam = playerCam.GetComponent <MouseLook>();

        MouseLook mouselook = GetComponent <MouseLook>();

        shotScript shotEn = GetComponent <shotScript>();

        PhotonView photonView = PhotonView.Get(this);

        //We enable the scripts only for our player, and not for the other players in the room
        if (photonView.isMine)
        {
            //MINE: local player, simply enable the local scripts
            mouselook.enabled = true;
            mouseCam.enabled  = true;
            armAim_D.enabled  = true;
            armAim_G.enabled  = true;
            shotEn.enabled    = true;

            playerCam.gameObject.active = true;
        }
        else
        {
            mouselook.enabled = false;
            armAim_D.enabled  = false;
            armAim_G.enabled  = false;
            shotEn.enabled    = false;

            mouseCam.enabled            = false;
            playerCam.gameObject.active = false;
            //playerControl.enabled = false;
        }

        gameObject.name = gameObject.name + photonView.viewID;

        //networkManager netMan= (networkManager)GameObject.Find("multiScripts").GetComponent("networkManager");
    }
Esempio n. 4
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        // is it a shot?
        shotScript shot = collider.gameObject.GetComponent <shotScript>();

        if (shot != null)
        {
            Destroy(shot.gameObject);
        }
    }
Esempio n. 5
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        shotScript shot = collider.gameObject.GetComponent <shotScript>();

        if (shot != null)
        {
            soundEffectScript.Instance.MakeExplosionSound();
            // same/other  team
            if (shot.team != team)
            {
                takeHealthOff();
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        //Getting the player transform
        //shotScript shotS=null;
        foreach (Transform child in transform.root)
        {
            if (child.name != "globalHUD" && child.name != "scoreBoardUI" && child.name != "InGameMenu" && child.name != "littleScoreBoardUI" && child.name != "PlayerHUD")
            {
                shotScript shotS = child.gameObject.GetComponent <shotScript>();
                reload     = shotS.isReloading;
                actualMun  = shotS.actualAmmo;
                maxMun     = shotS.mun_max;
                reloadStat = shotS.getReloadStatus();
            }
        }

        titleObj  = transform.Find("WeaponTitle");
        infoObj   = transform.Find("WeaponInfo");
        statusObj = transform.Find("ReloadStatus");

        titleText  = titleObj.GetComponent <Text>();
        infoText   = infoObj.GetComponent <Text>();
        statSlider = statusObj.GetComponent <Slider>();

        titleText.text = globalWeaponStats.weaponNames[0];

        //If we're not reloading
        if (!reload)
        {
            infoText.text = actualMun.ToString() + " | " + maxMun.ToString();
            statusObj.gameObject.active = false;
        }
        else
        {
            infoText.text = "RELOADING";

            statusObj.gameObject.active = true;
            statSlider.minValue         = 0f;
            statSlider.maxValue         = 100f;
            statSlider.value            = reloadStat;
        }
    }
Esempio n. 7
0
    void OnTriggerEnter2D(Collider2D trigger)
    {
        Debug.Log("Trigger enemy");
        enemyCounter--;
        Debug.Log(enemyCounter);

        shotScript laser = trigger.gameObject.GetComponent <shotScript>();

        if (laser != null)
        {
            health = health - laser.damage;
            if (health <= 0)
            {
                enemyExplosion();
                Destroy(gameObject, 0.0f);
                if (enemyCounter == 0)
                {
                    EnemySpawner spawner = gameObject.GetComponent <EnemySpawner>();
                    spawner.drawEnemies();
                }
            }
        }
    }