void OnTriggerEnter(Collider other) { TripControls boost = other.GetComponent <TripControls>(); // checks if object is tram if (boost) { boost.SpeedChange(boost.movSpeed * 3); // increases speed of tram based on current speed Destroy(this.gameObject); } }
void OnTriggerEnter(Collider other) { TripControls turning = other.GetComponent <TripControls>(); if (turning) { turning.Turning(); Destroy(this.gameObject); } }
void OnTriggerEnter(Collider other) { TripControls brake = other.GetComponent <TripControls>(); // checks if object is tram if (brake) { if (endPlatform) { brake.SpeedChange(0); // stops tram if speed gets too low. should mean it reached the end platform } else { brake.SpeedChange(brake.movSpeed / 3); // decreases speed of tram based on current speed Destroy(this.gameObject); } Destroy(this.gameObject); } }
void Update() { if (alive) { if (enemyType == Types.backAndForth) // enemy in a back and forth pattern along z { if (points == 0) { points = 10; } Vector3 currentPos = transform.position; transform.position = new Vector3(currentPos.x, currentPos.y, Mathf.Lerp(startPos.z, startPos.z + distance, time)); // enemy movement time += 0.5f * Time.deltaTime; if (time > maxTime) { startPos = transform.position; distance = -distance; time = 0.0f; transform.Rotate(0, 180, 0); // change direction on reaching max distance } } else if (enemyType == Types.upAndDown) // enemy in up and down pattern along y { if (points == 0) { points = 10; } Vector3 currentPos = transform.position; transform.position = new Vector3(currentPos.x, Mathf.Lerp(startPos.y, startPos.y + distance, time), currentPos.z); // enemy movement time += 0.5f * Time.deltaTime; if (time > maxTime) { startPos = transform.position; distance = -distance; time = 0.0f; } } else if (enemyType == Types.orbiting) // enemy movement along sphere (enemy needs to be attached to rotating sphere) { if (points == 0) { points = 20; } float rotSpeed = Random.Range(1.0f, 20.0f); transform.Rotate(0, rotSpeed, 0); } else if (enemyType == Types.mob) // enemy movement in a mob { if (points == 0) { points = 1; } if (body == null) { gameObject.AddComponent <Rigidbody>(); body = GetComponent <Rigidbody>(); body.freezeRotation = true; } Ray ray = new Ray(transform.position, transform.forward); RaycastHit tram; if (Physics.SphereCast(ray, 0.75f, out tram, 100f, layer)) // raycast checking for tram/player { if (tram.transform.gameObject) { GameObject hitObject = tram.transform.gameObject; dallas = hitObject.GetComponent <TripControls>(); if (dallas) // if player is spotted, look at { Vector3 playerPos = tram.transform.GetChild(5).position; transform.LookAt(playerPos); StartCoroutine(Run()); } } } if (dallas == null) { transform.Translate(0, 0, speed * Time.deltaTime); RaycastHit wall; if (Physics.SphereCast(ray, 0.75f, out wall)) // changes travel direction if obstacle is in the way { if (wall.distance < maxDistance) { float angle = Random.Range(-110, 110); transform.Rotate(0, angle, 0); } } } if (noticed) { transform.Translate(Random.Range(-0.01f, 0.01f), 0, speed * Time.deltaTime); } } } else { transform.Translate(Random.Range(-15, 15) * Time.deltaTime, Random.Range(-15, 15) * Time.deltaTime, Random.Range(-15, 15) * Time.deltaTime); // movement on death } }