void OnTriggerExit(Collider other) { if (pipeInContact != null) { pipeInContact.state = state = AxisPipeState.rotatingAndMoving; } pipeInContact = null; }
void OnTriggerEnter(Collider other) { pipeInContact = other.gameObject.GetComponent <AxisPipe>(); if (pipeInContact != null) { pipeInContact.state = state = AxisPipeState.rotating; } }
// Update is called once per frame void FixedUpdate() { if (Mathf.Abs(distanceTravelled) > distanceToTravelBeforeDespawn) { Destroy(gameObject); } if (stopped) { return; } switch (state) { case AxisPipeState.rotatingAndMoving: Rotate(); Move(); break; case AxisPipeState.moving: Move(); break; case AxisPipeState.rotating: Rotate(); if (pipeInContact != null) { float angleBetween = Quaternion.Angle(pipeInContact.transform.rotation, transform.rotation); float closeEnoughCutoff = 2; if ((angleBetween + closeEnoughCutoff) % 60 < closeEnoughCutoff) { pipeInContact.state = state = AxisPipeState.moving; } } break; } }
// Use this for initialization void Start() { state = AxisPipeState.rotatingAndMoving; }