protected virtual void OnHitByVehicle(BaseVehicleClass vehicle) { if (this.tag == "Zombie") { zombieKillSource = vehicle.GetComponentInChildren <AudioSource>(); if (health && health.health > 0) { if (!zombieKillSource.isPlaying) { zombieKillSource.PlayOneShot(zombieHit); } } } FallOnDeath fallOnDeath = GetComponent <FallOnDeath>(); if (fallOnDeath) { Vector3 toVehicle = vehicle.transform.position - transform.position; fallOnDeath.SetAxisToRotateAround(Vector3.Cross(-toVehicle.normalized, Vector3.up)); } if (health) { health.health = 0; } }
void AttachToVehicle(BaseVehicleClass vehicle) { vehicleAttachedTo = vehicle; //transform.parent = vehicleAttachedTo.transform; vehicleAttachedTo.AddZombieOnRoof(gameObject); GetComponent <SeekPlayer>().enabled = false; if (GetComponent <DieWhenHitByVehicle>()) { GetComponent <DieWhenHitByVehicle>().enabled = false; } rb.constraints |= RigidbodyConstraints.FreezePosition; Physics.IgnoreCollision(vehicleAttachedTo.GetComponent <Collider>(), GetComponent <ChangeColliderOnDeath>().aliveCollider); climbing = true; climbingPercentDone = 0; vehicleRigidbody = vehicleAttachedTo.GetComponent <Rigidbody>(); localStartClimbPosition = vehicleAttachedTo.transform.InverseTransformPoint(transform.position); localEndClimbPosition = localStartClimbPosition; localEndClimbPosition.y = 5.0f; localEndPosition = localEndClimbPosition * 0.5f;//towards centre of vehicle localEndPosition.y = localEndClimbPosition.y; //set end pos to point actually touching top of vehicle localEndPosition = vehicleAttachedTo.transform.InverseTransformPoint(vehicleRigidbody.ClosestPointOnBounds(vehicleAttachedTo.transform.TransformPoint(localEndPosition))); localEndClimbPosition.y = localEndPosition.y; }
private void TryEnterVehicle(BaseVehicleClass vehicle) { if (_occupyCooldown <= 0.0f && !_occupiedVehicle) { if (!Movement.InputLeft() && !Movement.InputRight()) { if (vehicle.health <= 0 || vehicle.GetFuelPercentage() <= 0) { return; } GameObject followCamera = gameObject.GetComponent <DisableVehicle>().followCamera; //if (followCamera == null) Debug.Log("null followcamera"); //if (followCamera.GetComponent<FollowCamera>() == null) Debug.Log("null followcamera component"); //if (followCamera.GetComponent<FollowCamera>().target == null) Debug.Log("null followcamera component target"); //if (vehicle == null) Debug.Log("null vehicle"); if (followCamera != null) { followCamera.GetComponent <FollowCamera>().target = vehicle.gameObject; } gameObject.GetComponent <DisableVehicle>().followCamera = null; vehicle.GetComponent <DisableVehicle>().followCamera = followCamera; vehicle.SetDriver(gameObject); EnterVehicle(vehicle); Camera.main.GetComponent <TransparentifyObject>().player = vehicle.transform; _occupiedVehicle = true; } } }
private void OnCollisionEnter(Collision collision) { if (collision.collider.gameObject.GetComponent <BaseVehicleClass>()) { BaseVehicleClass vehicle = collision.collider.GetComponent <BaseVehicleClass>(); TryEnterVehicle(vehicle); } }
void Start() { rb = GetComponent <Rigidbody>(); vehicleAttachedTo = null; GetComponent <Health>().onDeath += () => { DetachFromVehicle(); enabled = false; }; }
void OnTriggerEnter(Collider collider) { if (collider.CompareTag("Vehicle")) { BaseVehicleClass vehicle = collider.GetComponentInParent <BaseVehicleClass>(); if (vehicle.speed > 5.0f) { OnHitByVehicle(vehicle); } } }
public void ExitVehicle(BaseVehicleClass vehicle, Vector3 position) { gameObject.GetComponentInChildren <ZombieDetector>().enabled = true; transform.parent = null; transform.SetPositionAndRotation(position, Quaternion.Euler(0.0f, 0.0f, 0.0f)); transform.RotateAround(vehicle.transform.localPosition, Vector3.up, vehicle.transform.eulerAngles.y); GetComponent <Rigidbody>().useGravity = true; GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation; GetComponent <Collider>().enabled = true; SetOccupyCooldown(1.0f); _occupiedVehicle = false; }
protected override void OnHitByVehicle(BaseVehicleClass vehicle) { base.OnHitByVehicle(vehicle); GameObject bloodEffect = Instantiate(bloodEffectPrefab, transform.position + Vector3.up * 1.5f, Quaternion.identity); Vector3 fromVehicle = (transform.position - vehicle.transform.position).normalized; fromVehicle.y = 0; fromVehicle.Normalize(); bloodEffect.transform.rotation = Quaternion.LookRotation(fromVehicle, Vector3.up); GetComponent <Health>().health = 0; Destroy(gameObject); }
void Start() { vehicle = GetComponent <BaseVehicleClass>(); List <ParticleSystem> tempParticleSystems = new List <ParticleSystem>(); foreach (Transform wheel in skidEffectWheels) { GameObject skidEffect = Instantiate(skidParticleSystemPrefab, Vector3.zero, Quaternion.identity, wheel); skidEffect.transform.localPosition = Vector3.zero; ParticleSystem skidParticleSystem = skidEffect.GetComponent <ParticleSystem>(); tempParticleSystems.Add(skidParticleSystem); } skidParticleSystems = tempParticleSystems.ToArray(); SetParticleSystemsEnabled(false); }
public void DetachFromVehicle() { if (vehicleAttachedTo == null) { return; } transform.parent = null; vehicleAttachedTo.RemoveZombieFromRoof(gameObject); GetComponent <SeekPlayer>().enabled = true; if (GetComponent <DieWhenHitByVehicle>()) { GetComponent <DieWhenHitByVehicle>().enabled = true; } rb.constraints &= ~RigidbodyConstraints.FreezePosition; Physics.IgnoreCollision(vehicleAttachedTo.GetComponent <Collider>(), GetComponent <ChangeColliderOnDeath>().aliveCollider, false); climbing = false; vehicleAttachedTo = null; vehicleRigidbody = null; }
// Use this for initialization void Start() { vehicle = GetComponent <BaseVehicleClass>(); GameObject darkSmokeEffect = Instantiate(darkSmokeParticleSystemPrefab, Vector3.zero, Quaternion.identity, smokeEffectEngine); darkSmokeEffect.transform.localPosition = Vector3.zero; GameObject lightSmokeEffect = Instantiate(lightSmokeParticleSystemPrefab, Vector3.zero, Quaternion.identity, smokeEffectEngine); lightSmokeEffect.transform.localPosition = Vector3.zero; GameObject fireEffect = Instantiate(fireParticleSystemPrefab, Vector3.zero, Quaternion.identity, smokeEffectEngine); fireEffect.transform.localPosition = Vector3.zero; darkSmokeParticleSystem = darkSmokeEffect.GetComponent <ParticleSystem>(); lightSmokeParticleSystem = lightSmokeEffect.GetComponent <ParticleSystem>(); fireParticleSystem = fireEffect.GetComponent <ParticleSystem>(); }
void OnDeath() { Movement move = GetComponent <Movement>(); move.centerOfMass.Set(0.0f, 6.5f, 0.0f); move.speed = 0.0f; move.rotationAngle = 0.0f; GameObject cameraTarget = Camera.main.GetComponent <FollowCamera>().target; if (cameraTarget != gameObject) { BaseVehicleClass vehicle = cameraTarget.GetComponent <BaseVehicleClass>(); if (vehicle) { vehicle.health = 0; } } dead = true; }
protected override void OnHitByVehicle(BaseVehicleClass vehicle) { base.OnHitByVehicle(vehicle); if (breakEffectPrefab) { GameObject effect = Instantiate(breakEffectPrefab, transform.position + Vector3.up * 1.5f, transform.rotation); Vector3 fromVehicle = (transform.position - vehicle.transform.position).normalized; fromVehicle.y = 0; fromVehicle.Normalize(); effect.transform.rotation = Quaternion.LookRotation(fromVehicle, Vector3.up); Destroy(gameObject); } else { rb.constraints = RigidbodyConstraints.None; rb.isKinematic = false; Destroy(this);//remove script, doesn't need to be called again } }
void OnCollisionStay(Collision collision) { if (!enabled) { return; } if (vehicleAttachedTo == null) { BaseVehicleClass vehicle = collision.gameObject.GetComponent <BaseVehicleClass>(); if (vehicle) { if (vehicle.GetDriver() != null) { if (vehicle.speed < 5) { if (vehicle.GetNumZombiesOnRoof() < 5) { AttachToVehicle(vehicle); } } } } } }
protected virtual void EnterVehicle(BaseVehicleClass vehicle) { Transform driverTransform = vehicle.transform.Find("DriverTransform"); if (driverTransform == null) { gameObject.transform.Translate(0, 100, 0); } else { //place player on bike BikeLean bike = vehicle.GetComponent <BikeLean>(); bike.enabled = true; gameObject.transform.parent = driverTransform; gameObject.transform.localPosition = Vector3.zero; gameObject.transform.localRotation = Quaternion.identity; } GetComponent <Collider>().enabled = false; Rigidbody rb = GetComponent <Rigidbody>(); rb.useGravity = false; rb.constraints = RigidbodyConstraints.FreezeAll; gameObject.GetComponentInChildren <ZombieDetector>().enabled = false; // disable players zombie detector to prevent player using weapons while in vehicle }
void Start() { vehicle = GetComponent <BaseVehicleClass>(); }