void Start() { fireCooldown = fireCooldownMax; headCollider = GetComponentInChildren <HeadCollider>(); rigidbody = GetComponent <Rigidbody2D> (); ballHandler = GetComponentInChildren <BallHandler>(); KeyValuePair <int, Vector3> spawnData = gameHandler.spawn(); transform.position = spawnData.Value; inputs = new Inputs(spawnData.Key); InitControllers(); mAnimator = GetComponent <Animator>(); if (inputs.ID == 1) { ballHandler = transform.Find("BallRed").GetComponent <BallHandler>(); mAnimator.runtimeAnimatorController = controllerP1; } else { ballHandler = transform.Find("BallBlue").GetComponent <BallHandler>(); mAnimator.runtimeAnimatorController = controllerP2; } ballHandler.gameObject.SetActive(true); }
// Start is called before the first frame update void Start() { scoreText.text = currScore.ToString(); currTimer = tweakCountDown; timer.text = currTimer.ToString("0"); myBall = FindObjectOfType <BallHandler>(); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Ball") { BallHandler ball = collision.GetComponent <BallHandler>(); BallsManager.Instance.Balls.Remove(ball); ball.Die(); } }
public void ChangeBall() { if (ball != null) { ball.gameObject.SetActive(false); Destroy(ball.gameObject); } GameObject tempBall = Instantiate(ballPrefab, new Vector3(16f, 1f, 0.3f), Quaternion.identity); ball = tempBall.GetComponent <BallHandler>(); SaveLastBallName(); }
private void InitBall() { Vector3 paddlePosition = PaddleHandler.Instance.gameObject.transform.position; Vector3 startingPosition = new Vector3(paddlePosition.x, paddlePosition.y + .27f, 0); initialBall = Instantiate(ballPrefab, startingPosition, Quaternion.identity); initialBallRigidBody = initialBall.GetComponent <Rigidbody2D>(); this.Balls = new List <BallHandler> { initialBall }; }
private void ApplyCollisionLogic(BallHandler ball) { this.Hitpoints--; if (this.Hitpoints <= 0) { BricksManager.Instance.remainingBricks.Remove(this); OnBrickDestruction?.Invoke(this); SpawnDestroyEffect(); Destroy(this.gameObject); } else { this.spriteRenderer.sprite = BricksManager.Instance.sprites[this.Hitpoints - 1]; } }
/// <summary> /// Initial setup, called at startup. /// </summary> /// <remarks> /// In future versions of ML-agents (> 0.14), InitializeAgent should be replaced by Initialize. /// </remarks> public override void InitializeAgent() { base.InitializeAgent(); // Initialize joint controllers leftShoulder = new JointController("Left shoulder", leftShoulderJoint, new Vector3(-999, -999, -999), new Vector3(999, 999, 999)); //new Vector3(-999, -999, -25), new Vector3(999, 999, 25)); leftUpperArm = new JointController("Left upper arm", leftUpperArmJoint, new Vector3(-999, -999, -999), new Vector3(999, 999, 999)); leftElbow = new JointController("Left elbow", leftElbowJoint, new Vector3(-999, -999, -999), new Vector3(999, 999, 999)); //new Vector3(-25, -999, -999), new Vector3(25, 999, 999)); head = new JointController("Head", headJoint, new Vector3(-999, -999, -999), new Vector3(999, 999, 999)); // Retrieve the rubberArm and visuo-tactile stimulation objects from the environment rubberArmController = rubberArm.GetComponent <RubberArmController>(); ballScript = ballHandler.GetComponent <BallHandler>(); vibScript = vibHandler.GetComponent <VibHandler>(); // Set the head rotation (and subsequently the camera perspective) head.SetRelativeJointAngles(new Vector3(15f, -20f)); }
private void OnBallDeath(BallHandler ball) { if (BallsManager.Instance.Balls.Count <= 0) { this.Lives--; if (this.Lives < 1) { gameOverScreen.SetActive(true); } else { OnLifeLost?.Invoke(this.Lives); BallsManager.Instance.ResetBalls(); isGameStarted = false; BricksManager.Instance.LoadLevel(BricksManager.Instance.CurrentLevel); } } }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("Ball")) { if (!firstBall) { firstBall = true; BallsManager.Instance.CalculateNewScaleAndMax(multiplicator); Vibration.Vibrate(50, 50, true); } BallHandler ballScript = other.GetComponent <BallHandler>(); //checking if already been through if (ballScript.usedDuplicatorsId.Contains(GetInstanceID())) { overlappingBalls++; return; } //inherit used duplicators List <int> currentBallDuplicatorList = new List <int>(); currentBallDuplicatorList.AddRange(ballScript.usedDuplicatorsId); currentBallDuplicatorList.Add(GetInstanceID()); //triggered ball back to pool BallsManager.Instance.LoadIntoPool(other.gameObject); BallsManager.Instance.UpdatePlayableBalls(multiplicator - 1); StartCoroutine(SpawningCoroutine(multiplicator, currentBallDuplicatorList)); if (bouncyCoroutine != null) { StopCoroutine(bouncyCoroutine); } bouncyCoroutine = StartCoroutine(BouncyDisplayCoroutine()); } }
private void OnCollisionEnter(Collision other) { if (other.gameObject.GetComponent <BallHandler>()) { BallHandler ballHandler = other.gameObject.GetComponent <BallHandler>(); if (ballHandler.setAblaze) { StartCoroutine(SetOnFire()); } if (ballHandler.electryfy) { StartCoroutine(ElectryfyObsticle()); } } else if (other.gameObject.GetComponent <ObsticleHandler>()) { rigidbodyThis.AddForce(rigidbodyThis.velocity * -1f); StartCoroutine("StillCollision", rigidbodyThis.velocity * -1f); } else { GoBack(); } }
public void SpawnBall(bool isDuplicator, Transform spawnPolygon, List <int> previousUsedDuplicators) { //Spawner for duplicator and receivers GameObject newBall; if (sleepingBallsList.Count == 0) { newBall = Instantiate(BallsManager.Instance.ballPrefab, Vector3.up * 100, GameManager.Instance.GetCurrentBoard().transform.rotation, GameManager.Instance.GetCurrentBoard().transform); } else { newBall = UnloadBallFromPool(); newBall.transform.SetParent(GameManager.Instance.GetCurrentBoard().transform); newBall.SetActive(true); } BallHandler ballScript = newBall.GetComponent <BallHandler>(); //We add previously used duplicators to avoid loops ballScript.usedDuplicatorsId.AddRange(previousUsedDuplicators); newBall.transform.localScale = ballScript.baseScale * currentBallScale * Vector3.one; newBall.transform.position = RandomPositionInPolygon(spawnPolygon, newBall.transform.localScale.x); newBall.GetComponent <Collider>().enabled = true; ballsList.Add(newBall); }
private void Start() { ball = gameObject.GetComponent <BallHandler>().currentBall; _agent = GetComponent <NavMeshAgent>(); _ballHandler = GetComponent <BallHandler>(); }
private void OnCollisionEnter2D(Collision2D collision) { BallHandler ball = collision.gameObject.GetComponent <BallHandler>(); ApplyCollisionLogic(ball); }
// Start is called before the first frame update void Start() { ballHandlerScript = ballHandler.GetComponent <BallHandler>(); vibHandlerScript = vibHandler.GetComponent <VibHandler>(); }