// Start is called before the first frame update void Start() { rb = gameObject.GetComponent <SimpleRigidbody>(); ai = gameObject.GetComponent <EnemyAI>(); spriteRenderer = gameObject.GetComponent <SpriteRenderer>(); state = EnemyState.Idle; }
// Start is called before the first frame update void Start() { controller = gameObject.GetComponent <TopDownPlayerController>(); anim = gameObject.GetComponent <Animator>(); rb = gameObject.GetComponent <SimpleRigidbody>(); anim.SetFloat(DirectionXHash, rb.GetDirection().x); anim.SetFloat(DirectionYHash, rb.GetDirection().y); }
void Start() { //timer = 0f; state = PlayerState.Idle; rb = gameObject.GetComponent <SimpleRigidbody>(); knockbackTimer = knockbackTime; isI_frame = false; roomMovement = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <RoomTransitionMovement>(); roomMovement.OnRoomTransitionEnter += Freeze; roomMovement.OnRoomTransitionExit += Unfreeze; }
private void FixedUpdate() { // Auto Reload if (shotCount <= 0 && reloadStarted < 0) { reloadStarted = Time.time; } // Finish Reload after reloadTime if (reloadStarted >= 0 && Time.time - reloadStarted >= (ReloadTime * ReloadTimeMod)) { reloadStarted = -1; shotCount = Mathf.RoundToInt(MagazineCapacity * MagazineCapacityMod); } if (!safety && reloadStarted < 0 && (Time.time - lastShot) >= timePerRound && shotCount > 0) { ReadyToFire = true; } else { ReadyToFire = false; } // Fire Weapon if (fire && ReadyToFire) { // Update Counters lastShot = Time.time; --shotCount; ++shotsFired; // Fire Bullet Bullet bullet = (Bullet)bulletPoolManager.getPoolObject(bulletPrefab, muzzle.position, muzzle.rotation, typeof(Bullet)); Vector3 recoilImpulse = bullet.fireBullet(rigidbody != null ? rigidbody.velocity : Vector3.zero, Spread * SpreadMod, MuzzleEnergyModifier * MuzzleEnergyModifierMod); bullet.DamageMod = Damage * DamageMod; // Recoil if (rigidbody != null) { rigidbody.AddForce(recoilImpulse, ForceMode.Impulse); } float recoilStrength = recoilImpulse.magnitude; verticalAccumulatedRecoil += VerticalRecoil * RecoilMod * recoilStrength * Random.Range(0.0f, 1.0f); horizontalAccumulatedRecoil += HorizontalRecoil * RecoilMod * recoilStrength * Random.Range(-1.0f, 1.0f); transform.localRotation *= Quaternion.AngleAxis(verticalAccumulatedRecoil, Vector3.left); transform.localRotation *= Quaternion.AngleAxis(horizontalAccumulatedRecoil, Vector3.up); // Eject Casing if (ejectionPort != null && casingPrefab != null) { SimpleRigidbody casing = (SimpleRigidbody)casingPoolManager.getPoolObject(casingPrefab, ejectionPort.position, ejectionPort.rotation, typeof(SimpleRigidbody)); casing.Velocity = ejectionPort.rotation * (casingVelocity + (Random.insideUnitSphere * casingDeviation)); if (rigidbody != null) { casing.Velocity += rigidbody.velocity; } } // Firemode Limitations if (fireModes[fireMode] != 0 && shotsFired >= fireModes[fireMode]) { fire = false; } // Fire Sound if (fireSound != null) { audioSource.clip = fireSound; audioSource.Play(); } } // Recenter Weapon verticalAccumulatedRecoil -= verticalAccumulatedRecoil * (recoilResetFactor * Time.deltaTime); horizontalAccumulatedRecoil -= horizontalAccumulatedRecoil * (recoilResetFactor * Time.deltaTime); float recoilAngle = Quaternion.Angle(transform.localRotation, originalRotation); transform.localRotation = Quaternion.RotateTowards(transform.localRotation, originalRotation, recoilAngle * recoilResetFactor * Time.deltaTime); // Toggle Safety // Complex Checking with multiple Variables to avoid firing Shots in the Frame in which the Safety is toggled if (disengageSafety) { safety = false; disengageSafety = false; } }
// Start is called before the first frame update void Start() { rb = gameObject.GetComponent <SimpleRigidbody>(); controller = gameObject.GetComponent <TopDownPlayerController>(); anim = gameObject.GetComponent <Animator>(); }
private void Awake() { rigidbody = gameObject.GetComponent <SimpleRigidbody>(); fragmentPoolManager = new PoolManager(); init(); }