public void FreeDisk(DiskData _disk) { DiskData theDisk = null; foreach (DiskData _Disk in used) { if (_Disk.innerDiskCount == _disk.innerDiskCount) { theDisk = _Disk; } } if (theDisk != null) { theDisk.reset(); free.Add(theDisk); used.Remove(theDisk); } }
// if click the disk void FixedUpdate() { if (Input.GetButtonDown("Fire1")) { Vector3 mouse = Input.mousePosition; Camera ca = cam.GetComponent <Camera>(); Ray ray = ca.ScreenPointToRay(mouse); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.collider.gameObject.tag.Contains("Disk")) // if hit the disk { DiskData theDisk = hit.collider.gameObject.GetComponent <DiskData>(); theDisk.reset(); FreeDisk(theDisk); ScoreRecorder a = Singleton <ScoreRecorder> .Instance; a.Record(theDisk); // get score } } } }
public void fixedUpdate(DiskData disk) { Rigidbody rigid = disk.gameObject.GetComponent <Rigidbody>(); if (disk.isEnabled && disk.transform.position != disk.pointB) { disk.currentTimeCount++; if (rigid) { rigid.velocity = new Vector3(Random.Range(-5f, 5f), (10f / 4) + Random.Range(-4f, 2f), 15f); disk.currentAngle.x = -Mathf.Atan((disk._speed.y + disk.Gravity.y) / disk._speed.z) * Mathf.Rad2Deg; transform.eulerAngles = disk.currentAngle; } } if (disk.reachedEnd) // if it has reached the end and not get clicked { disk.reset(); rigid.velocity = Vector3.zero; Singleton <DiskFactory> .Instance.FreeDisk(disk); } }