IEnumerator flash() { while (pressbutton) { yield return(new WaitForSeconds(0.3f)); onoff = onoff == true ? false : true; if (onoff == true) { if (kanan == true) { reteng.RetengKiri(false); reteng.RetengKanan(true); } else if (kiri == true) { reteng.RetengKanan(false); reteng.RetengKiri(true); } } else if (onoff == false) { if (kanan == true) { reteng.RetengKanan(false); } else if (kiri == true) { reteng.RetengKiri(false); } } } }
public void sensors() { int layer_mask = LayerMask.GetMask("boundary", "cars", "player"); RaycastHit hit; Vector3 SensorStartPos = transform.position; SensorStartPos += transform.forward * frontpos.x; float belokMultiplier = 0; BelokSendiri = false; SensorStartPos += transform.up * frontpos.y; //depan if (Physics.Raycast(SensorStartPos, transform.forward, out hit, sensorsLength, layer_mask)) { if (hit.collider.CompareTag("Boundary") || hit.collider.CompareTag("Player")) { BelokSendiri = true; Debug.DrawLine(SensorStartPos, hit.point); } if (hit.collider.CompareTag("Lampumerah") || hit.collider.CompareTag("Cars") || hit.collider.CompareTag("Palang")) { Ngerem = true; Debug.DrawLine(SensorStartPos, hit.point); } } else { BelokSendiri = false; Ngerem = false; Debug.DrawLine(SensorStartPos, hit.point); } SensorStartPos += transform.right * sidePos; //kanan if (Physics.Raycast(SensorStartPos, transform.forward, out hit, sensorsLength, layer_mask)) { if (hit.collider.CompareTag("Boundary") || hit.collider.CompareTag("Cars") || hit.collider.CompareTag("Player")) { BelokSendiri = true; belokMultiplier -= 1f; Debug.DrawLine(SensorStartPos, hit.point); } else { BelokSendiri = false; Debug.DrawLine(SensorStartPos, hit.point); } } //serongkanan else if (Physics.Raycast(SensorStartPos, Quaternion.AngleAxis(SensorAngle, transform.up) * transform.forward, out hit, sensorsLength, layer_mask)) { if (hit.collider.CompareTag("Boundary") || hit.collider.CompareTag("Cars") || hit.collider.CompareTag("Player")) { BelokSendiri = true; Debug.DrawLine(SensorStartPos, hit.point); belokMultiplier -= 0.5f; } else { BelokSendiri = false; Debug.DrawLine(SensorStartPos, hit.point); } } //kiri SensorStartPos -= transform.right * sidePos * 2; if (Physics.Raycast(SensorStartPos, transform.forward, out hit, sensorsLength, layer_mask)) { if (hit.collider.CompareTag("Boundary") || hit.collider.CompareTag("Cars") || hit.collider.CompareTag("Player")) { BelokSendiri = true; Debug.DrawLine(SensorStartPos, hit.point); belokMultiplier += 1f; } else { BelokSendiri = false; Debug.DrawLine(SensorStartPos, hit.point); } } //serongkiri else if (Physics.Raycast(SensorStartPos, Quaternion.AngleAxis(-SensorAngle, transform.up) * transform.forward, out hit, sensorsLength, layer_mask)) { if (hit.collider.CompareTag("Boundary") || hit.collider.CompareTag("Cars") || hit.collider.CompareTag("Player")) { BelokSendiri = true; Debug.DrawLine(SensorStartPos, hit.point); belokMultiplier += 0.5f; } else { BelokSendiri = false; Debug.DrawLine(SensorStartPos, hit.point); } } if (belokMultiplier == 0) { if (Physics.Raycast(SensorStartPos, transform.forward, out hit, sensorsLength, layer_mask)) { if (hit.collider.CompareTag("Boundary") || hit.collider.CompareTag("Cars") || hit.collider.CompareTag("Player")) { BelokSendiri = true; Debug.DrawLine(SensorStartPos, hit.point); if (hit.normal.x < 0) { belokMultiplier = -1; } else { belokMultiplier = 1; } } else { BelokSendiri = false; Debug.DrawLine(SensorStartPos, hit.point); } } } if (BelokSendiri) { frontLW.steerAngle = maksimalarahsetir * belokMultiplier; FrontRW.steerAngle = maksimalarahsetir * belokMultiplier; } if (belokMultiplier < 0) { LM.RetengKiri(true); LM.RetengKanan(false); } else if (belokMultiplier > 0) { LM.RetengKiri(false); LM.RetengKanan(true); } else { LM.RetengKiri(false); LM.RetengKanan(false); } }