IEnumerator _Down(GunHolder g, bool reload) { while (t < readyTime / 2) { transform.localPosition = Vector3.Lerp(originalPos, originalPos + (Vector3.up * downYoffset), t / (readyTime / 2)); t += Time.deltaTime; yield return null; } t = 0; transform.localPosition = originalPos + (Vector3.up * downYoffset); if (g) {g.UpdateSelectedGun();gameObject.SetActive(false);} if (reload) { int reloadAmmo = Mathf.Clamp(maxAmmo - ammo, 0, p.stockAmmo); float s = (1 - (float)reloadAmmo / (float)maxAmmo) * reloadTime; float tim = s; if (float.IsNaN(tim)) tim = 0; while (tim < reloadTime) { p.ammoText.text = Mathf.Ceil(tim / reloadTime * (float)maxAmmo) + ""; p.stockAmmoText.text = Mathf.Ceil((float)p.stockAmmo - ((tim - s / reloadTime) * (float)maxAmmo)) + ""; tim += Time.deltaTime; yield return null; } ammo += reloadAmmo; p.stockAmmo -= reloadAmmo; p.ammoText.text = ammo + ""; p.stockAmmoText.text = p.stockAmmo + ""; UpdateAmmoDisplay(); Up(); } }
void SwitchGun(int whichGun) { switch (whichGun) { case 1: currentGun = inv.gunOne; break; case 2: currentGun = inv.gunTwo; break; } }
public override void Save(GameObject obj) { SourcePlayer p = obj.GetComponent <SourcePlayer> (); if (p == null) { throw new UnityException("Tried to save a gameobject as a SourcePlayer, but it isn't one!"); } this.pos = p.transform.position; this.rot = p.transform.rotation; this.velocity = p.velocity; this.gravity = p.gravity; this.baseFriction = p.baseFriction; this.maxSpeed = p.maxSpeed; this.groundAccelerate = p.groundAccelerate; this.groundDecellerate = p.groundDecellerate; this.airAccelerate = p.airAccelerate; this.airStrafeAccelerate = p.airStrafeAccelerate; this.airSpeedBonus = p.airSpeedBonus; this.airSpeedPunish = p.airSpeedPunish; this.airBreak = p.airBreak; this.walkSpeed = p.walkSpeed; this.jumpSpeed = p.jumpSpeed; this.fallSoundThreshold = p.fallSoundThreshold; this.fallPunchThreshold = p.fallPunchThreshold; this.maxSafeFallSpeed = p.maxSafeFallSpeed; this.jumpSpeedBonus = p.jumpSpeedBonus; this.health = p.health; this.mass = p.mass; MouseLook m = obj.GetComponent <MouseLook> (); if (m == null) { throw new UnityException("Tried to save a gameobject as a SourcePlayer, but it isn't one!"); } this.headrotX = m.rotX; this.headrotY = m.rotY; GunHolder g = obj.GetComponent <GunHolder> (); if (g == null) { throw new UnityException("Tried to save a gameobject as a SourcePlayer, but it isn't one!"); } guns = new GunSaveData[g.Guns.Count]; int i = 0; foreach (GunBase gun in g.Guns) { guns[i] = new GunSaveData(gun.gameObject); i++; } this.equippedGun = g.Guns.IndexOf(g.EquippedGun); }
// Use this for initialization void Start () { ammoText = GameObject.FindGameObjectWithTag("AmmoText").GetComponent<Text>(); inv = GetComponent<PlayerController>().inv; //TESTING REMOVE PLS// inv.gunOne = new GunHolder(true,g1,0); inv.gunTwo = new GunHolder(true,g2,0); currentReloadTime = inv.gunOne.gun.reloadTime; currentGun = inv.gunOne; }
// Start is called beforz the first frame update void Start() { health = maxHealth; startPos = transform.position; nameTag.text = photonView.Owner.NickName; controller = GetComponent <CharacterController>(); debugController = GetComponent <DebugController>(); audioManager = GetComponent <AudioManager>(); m_camera = Camera.main; animator = GetComponent <Animator>(); SetAnimation("isIdle", true); StartCoroutine("WaitForLoad"); UpdateHealthUI(); gunHolderScript = gunHolder.GetComponent <GunHolder>(); photonView.RPC(nameof(SetupPartyHealthBars), RpcTarget.AllBufferedViaServer); StartCoroutine(PlayRepeatingWalkSoundEffect()); }
// Use this for initialization void Start() { gunHolder = transform.Find("GunHolder").GetComponent <GunHolder>(); audPlayer = GetComponent <AudioSource>(); cam = Camera.main; paddleList = new string[] { "Paddle-3", "Paddle-2", "Paddle-1", "PaddleRegular", "Paddle+1", "Paddle+2", "Paddle+3" }; gun1X = new float[] { 1.58f, 4f, 6.9f, 9f, 11.42f, 14.12f, 16.2f, 19.2f }; gun2X = new float[] { -2.46f, -5f, -7.21f, -10.14f, -12.72f, -15.22f, -18.08f, -20.17f }; ball = GameObject.Find("Ball"); Vector3 toObjectVector = new Vector3(); toObjectVector = transform.position - cam.transform.position; linearDistanceVector = Vector3.Project(toObjectVector, cam.transform.forward); actualDistance = linearDistanceVector.magnitude; playerPos = gameObject.transform.position; xPos = playerPos.x; paddle = transform.Find("Paddle"); }
public override GameObject Load() { GameObject obj = GameObject.Instantiate(ResourceManager.GetResource <GameObject>("Player")); SourcePlayer ps = obj.GetComponent <SourcePlayer> (); if (!ps) { throw new UnityException("Tried to load a gameobject as a SourcePlayer, but it isn't one!"); } ps.transform.position = this.pos; ps.transform.rotation = this.rot; ps.velocity = this.velocity; ps.gravity = this.gravity; ps.baseFriction = this.baseFriction; ps.maxSpeed = this.maxSpeed; ps.groundAccelerate = this.groundAccelerate; ps.groundDecellerate = this.groundDecellerate; ps.airAccelerate = this.airAccelerate; ps.airStrafeAccelerate = this.airStrafeAccelerate; ps.airSpeedBonus = this.airSpeedBonus; ps.airSpeedPunish = this.airSpeedPunish; ps.airBreak = this.airBreak; ps.walkSpeed = this.walkSpeed; ps.jumpSpeed = this.jumpSpeed; ps.fallSoundThreshold = this.fallSoundThreshold; ps.fallPunchThreshold = this.fallPunchThreshold; ps.maxSafeFallSpeed = this.maxSafeFallSpeed; ps.jumpSpeedBonus = this.jumpSpeedBonus; ps.health = this.health; ps.mass = this.mass; MouseLook m = obj.GetComponent <MouseLook> (); if (m == null) { throw new UnityException("Tried to save a gameobject as a SourcePlayer, but it isn't one!"); } m.SetRotation(Quaternion.Euler(this.headrotX, this.headrotY, 0)); GunHolder g = obj.GetComponent <GunHolder> (); if (g == null) { throw new UnityException("Tried to save a gameobject as a SourcePlayer, but it isn't one!"); } // Recreate all our guns, with the same stats and place them into inventory. g.Guns.Clear(); foreach (GunSaveData gundata in this.guns) { GameObject gun = gundata.Load(); GunBase realgun = gun.GetComponent <GunBase> (); realgun.player = obj.GetComponent <SourcePlayer>(); realgun.equipped = false; g.Guns.Add(realgun); } if (this.equippedGun != -1 && this.equippedGun < g.Guns.Count) { g.EquippedGun = g.Guns [this.equippedGun]; g.EquippedGun.OnEquip(obj); g.EquippedGun.equipped = true; } // Done! return(obj); }
void Awake() { playerController = FindObjectOfType <PlayerController>(); playerHealth = playerController.GetComponent <CharacterHealth>(); gunHolder = playerController.GetComponent <GunHolder>(); }
void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "powerup") { audPlayer.clip = sounds[1]; audPlayer.Play(); } if (collision.gameObject.name == "PowerUp-enlarge") { Destroy(collision.gameObject); if (currentPaddle < paddleList.Length - 1) { transform.Find(paddleList[currentPaddle]).gameObject.SetActive(false); currentPaddle++; transform.Find(paddleList[currentPaddle]).gameObject.SetActive(true); gun1.transform.localPosition = new Vector3(gun1X[currentPaddle], gun1.transform.localPosition.y, gun1.transform.localPosition.z); gun2.transform.localPosition = new Vector3(gun2X[currentPaddle], gun2.transform.localPosition.y, gun2.transform.localPosition.z); gunHolder = transform.Find("GunHolder").GetComponent <GunHolder>(); } } else if (collision.gameObject.name == "PowerUp-shrink") { Destroy(collision.gameObject); if (currentPaddle > 1) { transform.Find(paddleList[currentPaddle]).gameObject.SetActive(false); currentPaddle--; transform.Find(paddleList[currentPaddle]).gameObject.SetActive(true); gun1.transform.localPosition = new Vector3(gun1X[currentPaddle], gun1.transform.localPosition.y, gun1.transform.localPosition.z); gun2.transform.localPosition = new Vector3(gun2X[currentPaddle], gun2.transform.localPosition.y, gun2.transform.localPosition.z); gunHolder = transform.Find("GunHolder").GetComponent <GunHolder>(); } score.GetComponent <score>().gameScore += 5; } else if (collision.gameObject.name == "PowerUp-split") { Destroy(collision.gameObject); ball = GameObject.Find("Ball"); if (true) { ballClone = Instantiate(ballPrefab, ball.transform.position, Quaternion.identity); ballClone.transform.GetComponent <ballz>().ballInPlay = true; ballClone.gameObject.name = "Ball"; Rigidbody ballCloneRb = ballClone.GetComponent <Rigidbody>(); ballCloneRb.isKinematic = false; Vector3 newVelocity = ball.GetComponent <Rigidbody>().velocity; newVelocity.x *= -1; ballCloneRb.velocity = newVelocity; GameManager.instance.currentBalls++; if (firebalActive) { fireEff = ballClone.transform.Find("fx_fire_a"); fireEff.gameObject.SetActive(true); ballClone.transform.localScale = new Vector3(7.5f, 7.5f, 7.5f); ballClone.GetComponent <ballz>().damage = 5; } } } else if (collision.gameObject.name == "PowerUp-fireball") { Destroy(collision.gameObject); firebalActive = true; foreach (GameObject ball in GameObject.FindGameObjectsWithTag("Ball")) { fireEff = ball.transform.Find("fx_fire_a"); fireEff.gameObject.SetActive(true); ball.transform.localScale = new Vector3(7.5f, 7.5f, 7.5f); ball.GetComponent <ballz>().damage = 5; } score.GetComponent <score>().gameScore += 5; //ball = GameObject.Find("Ball"); //make the ball fireball } else if (collision.gameObject.name == "PowerUp-ballSpeed") { Destroy(collision.gameObject); foreach (GameObject ball in GameObject.FindGameObjectsWithTag("Ball")) { ball.GetComponent <ballz>().ballSpeed = 170 * ball.GetComponent <ballz>().initialBallSpeed; } } else if (collision.gameObject.name == "PowerUp-life") { Destroy(collision.gameObject); GameManager.instance.GetLife(); } else if (collision.gameObject.name == "PowerUp-death") { Destroy(collision.gameObject); GameManager.instance.LoseLife(); } else if (collision.gameObject.name == "PowerUp-Gun") { Destroy(collision.gameObject); gunActive = true; transform.Find("GunHolder").gameObject.SetActive(true); } }
protected virtual void Awake() { CharacterMotor = GetComponent <CharacterMotor>(); GunHolder = GetComponent <GunHolder>(); }
public void Down(GunHolder g, bool reload = false) { isReady = false; transform.localRotation = Quaternion.identity; StartCoroutine(_Down(g, reload)); }