void Start() { player1 = GameObject.FindGameObjectWithTag("Player1"); player2 = GameObject.FindGameObjectWithTag("Player2"); player1Script = player1.GetComponent <SCR_PlayerInput>(); player2Script = player2.GetComponent <SCR_PlayerInput>(); _currentBombTimer = Random.Range(minimumTimerRange, maximumTimerRange); _currentPlayer1Pos = player1.transform.position; _currentPlayer2Pos = player2.transform.position; }
IEnumerator moveBullet(Vector3 hitPoint) { currentTrail = Instantiate(sonarBullet, turretEndPosition.transform.position, Quaternion.identity); bMovingBullet = true; currentTrail.transform.LookAt(hitPoint); Vector3 startPos = turretEndPosition.transform.position + currentTrail.transform.forward * 2.0f; float distance = Vector3.Distance(startPos, hitPoint); float timerVariable = (distance / 100.0f) * shotSpeedMultiplier; float t = 0.0f; while (t < timerVariable) { t += Time.deltaTime; currentTrail.transform.position = Vector3.Lerp(startPos, hitPoint, t / timerVariable); yield return(null); } if (currentTrail) { Collider[] hitColliders = Physics.OverlapSphere(currentTrail.transform.position, damageRadius); int i = 0; while (i < hitColliders.Length) { //damage players with mDamage if (hitColliders[i].gameObject.CompareTag("PlayerTrigger")) { playerHealth = hitColliders[i].transform.parent.transform.parent.GetComponent <SCR_PlayerHealth>(); if (playerHealth) { playerHealth.DamagePlayer(damagePerShot); //stun code playerInputScr = playerHealth.gameObject.GetComponent <SCR_PlayerInput>(); StartCoroutine(playerInputScr.SlowPlayer(stunSpeed, stunTime)); } } i++; } Destroy(currentTrail); bMovingBullet = false; } bHitPointActive = true; hitTrail = Instantiate(sonarHit, hitPoint, Quaternion.identity); hitTrail.transform.LookAt(turretEndPosition.transform.position); if (hitTrail) { Destroy(hitTrail, 0.3f); bHitPointActive = false; } }
void Awake() { _attackScript = gameObject.GetComponent <SCR_PlayerAttack>(); _inputScript = GetComponent <SCR_PlayerInput>(); uiManagerScript = GameObject.FindGameObjectWithTag("UIManager").GetComponent <SCR_UIManager>(); //reset playerWeaponUI once for both players if (gameObject.tag == "Player1") { SCR_UIManager.instance.ResetWeaponSlots(); } _gunInventory = new STR_GunInventory[numberOfWeapons]; for (int i = 0; i < numberOfWeapons; i++) { _gunInventory[i].currentAmmo = 100; } _gunInventory[numberOfWeapons - 1].gunObject = grenade; _gunInventory[numberOfWeapons - 1].currentAmmo = 5; Transform gunPos = _inputScript.gunPosition; GameObject infiniteGun = Instantiate(infinitePistolPrefab, gunPos.transform.position, new Quaternion(0, 180, 0, 0)); infiniteGun.transform.parent = gunPos; infiniteGun.transform.rotation = new Quaternion(0, 0, 0, 0); _gunInventory[2].gunObject = infiniteGun; _gunInventory[2].currentAmmo = 100; uiManagerScript.SetCurrentAmmoText(gameObject.tag, 0.0f, 0, 0, true); _currentWeaponInterface = (IWeapon)infiniteGun.GetComponent(typeof(IWeapon)); _currentWeaponInterface.SetParent(gameObject); _attackScript.UpdateWeaponInterface(_currentWeaponInterface); _currentlySelectedWeapon = 2; _inputScript.SpeedMultiplier = speedMultipler; GetComponent <SCR_PlayerHealth>().HealthMultiplier = healthMultiplier; weaponSwitchingSource = GetComponent <AudioSource>(); uiManagerScript.SwitchGunImages(gameObject.tag, false, ThrowableType.FireGrenade, true); uiManagerScript.SwitchSelectedWeaponUI(gameObject.tag, _currentlySelectedWeapon); playerWorldSpaceUIScr = GetComponent <SCR_PlayerWorldSpaceUI>(); MAX_TRG_SCL = GetComponent <SCR_PlayerAttack>().MAX_TRG_SCL; }