void OnCollisionEnter(Collision collision) { // if the collision object has BallChainMovement // then it is in the chain BallChainMovement ballChainMovement = collision.gameObject .GetComponent <BallChainMovement>(); if (ballChainMovement != null && !registered && GetComponent <Rigidbody> ().isKinematic == false) { MovementRegistrationEntry entry = new MovementRegistrationEntry(); entry.bulletBall = gameObject; entry.chainBall = collision.gameObject; entry.proceedTime = 0f; entry.registerFrame = Time.frameCount; entry.repeatChainBall = 0; chainMovement.RegisterInsertion(entry); registered = true; GetComponent <Rigidbody> ().isKinematic = true; GetComponent <Rigidbody> ().velocity = Vector3.zero; } else if (ballChainMovement == null && !registered) { collisionCount++; } }
void InsertBlueBall() { GameObject bBall = Instantiate(blueBallPrefab, spawnPoint.transform.position, Quaternion.identity) as GameObject; countBlue++; bBall.name = "Blue" + countBlue; BallChainMovement ballScript = bBall.AddComponent <BallChainMovement> (); ballScript.SetPPS(forwardPercentagePerSecond, backwardPercentagePerSecond); bBall.tag = "Blue"; foreach (GameObject b in ballChain) { //b.GetComponent<BallChainMovement>().moveFlag=false; } // bBall.transform.parent = chain.transform; ballChain.Add(bBall); bBall.transform.parent = balls; // if (ballChain.Count == 1) // { // head = bBall; // bBall.AddComponent<BallChainMovement> (); // Debug.Log ("Head is" + head.name); // } // else // { // bBall.transform.parent=head.transform; // bBall.AddComponent<ChildBallMovement> (); // } // bBall.AddComponent<BallChainMovement> (); }
// void InsertCounterMagicBall() { GameObject cmBall = Instantiate(counterMagicBallPrefab, spawnPoint.transform.position, Quaternion.identity) as GameObject; cmBall.name = "CounterMagic"; BallChainMovement ballScript = cmBall.AddComponent <BallChainMovement> (); ballScript.SetPPS(forwardPercentagePerSecond, backwardPercentagePerSecond); cmBall.tag = "CounterMagic"; foreach (GameObject b in ballChain) { //b.GetComponent<BallChainMovement>().moveFlag=false; } // bBall.transform.parent = chain.transform; ballChain.Add(cmBall); cmBall.transform.parent = balls; }
public void SetPPSForBallScript(BallChainMovement ballScript) { ballScript.SetPPS(forwardPercentagePerSecond, backwardPercentagePerSecond); }
void UpdateInsertion() { // Move chain and Add bullet to chain int dequeSize = 0; foreach (MovementRegistrationEntry entry in insertionQueue) { if (Time.frameCount > entry.registerFrame) { // move all the leading balls foreach (GameObject ball in balls) { float deltaTime = Time.deltaTime; if (entry.proceedTime + deltaTime > insetionSmoothTime) { deltaTime = insetionSmoothTime - entry.proceedTime; } ball.GetComponent <BallChainMovement>() .PushFoward(diameterPercentPerSecond * deltaTime); if (ball == entry.chainBall) { break; } } entry.proceedTime += Time.deltaTime; // TODO: Fix the bug of position mismatch when multiple bullets // hit same chainBall if (entry.proceedTime > insetionSmoothTime) { dequeSize++; int idx = balls.IndexOf(entry.chainBall); if (entry.repeatChainBall > 1) { Debug.Log("Same Time"); } if (idx + entry.repeatChainBall >= balls.Count) { Debug.LogWarning("Insertion idx Larger than chain size"); } balls.Insert(idx + entry.repeatChainBall, entry.bulletBall); // Synchronizing the remove CheckColorTableEntry setEntry = new CheckColorTableEntry(); setEntry.indexReference = idx + entry.repeatChainBall; setEntry.covered = false; if (!checkColorTable.ContainsKey(entry.bulletBall)) { checkColorTable.Add(entry.bulletBall, setEntry); } else { Debug.LogError("Same bulletBall registered twice " + entry.bulletBall); } combo = 0; checkColorRegisterTime = Time.time; //Debug.Log (entry.bulletBall.name + " " + entry.chainBall.name + " " + (idx)); entry.bulletBall.GetComponent <Rigidbody> ().isKinematic = false; entry.bulletBall.transform.parent = ballsObject.transform; BallChainMovement ballScript = entry.bulletBall .AddComponent <BallChainMovement>(); ballScript.currPathPercent = entry.chainBall.GetComponent <BallChainMovement> ().currPathPercent - (entry.repeatChainBall) * diameterPercent; spawn.SetPPSForBallScript(ballScript); } } else { // as it is enqued in time order break; } } DequeHeadElements(dequeSize); // Move bullet }
public void SetPPSForBallScript (BallChainMovement ballScript) { ballScript.SetPPS(forwardPercentagePerSecond, backwardPercentagePerSecond); }