void Update() { // Récuperation et detection des socles GameObject Sce1 = GameObject.Find("Socle 1"); Socle_1 Sce1Script = Sce1.GetComponent <Socle_1>(); GameObject Sce2 = GameObject.Find("Socle 2"); Socle_2 Sce2Script = Sce2.GetComponent <Socle_2>(); if (Sce1Script.TotalForce != 10 && Sce1Script.TotalForce == Sce2Script.TotalForce) { if (body.rotation.z > -0.01 && body.rotation.z < 0.01) { body.constraints = RigidbodyConstraints.FreezeAll; if (!tabAppear) { tabAppear = !tabAppear; GetComponent <GenerateTablette>().Spawn(); } } else { this.body.angularVelocity = body.rotation.z > 0 ? new Vector3(0, 0, -0.5f) : body.rotation.z < 0 ? new Vector3(0, 0, 0.5f) : Vector3.zero; } } else { dropTimer = 0; } }
private void FixedUpdate() // AR { GameObject Sce1 = GameObject.Find("Socle 1"); Socle_1 Sce1Script = Sce1.GetComponent <Socle_1>(); GameObject Sce2 = GameObject.Find("Socle 2"); Socle_2 Sce2Script = Sce2.GetComponent <Socle_2>(); float coordZ, force; force = Sce1Script.TotalForce - 10; coordZ = force.Map(0, (Sce1Script.TotalForce - 10) + (Sce2Script.TotalForce - 10), -20, 20); if (Math.Abs(Math.Abs(body.transform.rotation.eulerAngles.z.Euler()) - Math.Abs(coordZ)) < 0.5f) { rotate = false; } else if (Math.Abs(body.transform.rotation.eulerAngles.z.Euler()) > 20) { rotate = false; } else { rotate = true; } if (rotate) { body.transform.Rotate((coordZ > body.transform.rotation.eulerAngles.z.Euler() ? Vector3.forward : Vector3.back) * Time.deltaTime * 10, Space.World); } }
// Inistialisation de la barre void Start() { // Gestion du Rigiboby de la Barre de la balance this.body = GetComponent <Rigidbody>(); // Récuperation et detection des socles GameObject Sce1 = GameObject.Find("Socle 1"); Socle_1 Sce1Script = Sce1.GetComponent <Socle_1>(); GameObject Sce2 = GameObject.Find("Socle 2"); Socle_2 Sce2Script = Sce2.GetComponent <Socle_2>(); // this.body.constraints = RigidbodyConstraints.FreezePosition | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ; }