// Start is called before the first frame update void Start() { ballStats = ball.GetComponent <BallStats>(); ballList = new List <GameObject>(); timePassed = 0; }
private void SetCharacter(Data.CharacterInfo c) { GetComponent <Renderer>().material = c.material; GetComponent <TrailRenderer>().material = c.trail; if (c.name == "Super Sanic" && ActiveData.GameSettings.eSportsReady) { GetComponent <TrailRenderer>().material = ActiveData.ESportsTrail; } transform.localScale = new Vector3(c.ballSize, c.ballSize, c.ballSize); if (c.alternativeMesh != null) { GetComponent <MeshFilter>().mesh = c.alternativeMesh; } //set collision mesh too if (c.collisionMesh != null) { if (c.collisionMesh.vertexCount <= 255) { Destroy(GetComponent <Collider>()); MeshCollider mc = gameObject.AddComponent <MeshCollider>(); mc.sharedMesh = c.collisionMesh; mc.convex = true; } else { Debug.LogWarning("Vertex count for " + c.name + "'s collision mesh is bigger than 255!"); } } characterStats = c.stats; }
public void DestroyBall(GameObject ball, List <GameObject> ballList, EffectOnBallDestroy effectFunc) { BallStats ballStats = ball.GetComponent <BallStats>(); if (ballStats.WasHitByDestroyer(destroyerIndex)) { return; } Ray ray = new Ray(ball.transform.position, Vector3.down); RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, 0.2f); // if the collider doesnt detect anything, try changing length of the raycast to bigger than radius of a ball if (hit.collider) { if (hit.collider.tag == "BallDestroyer" && hit.collider.name == this.name) // if raycast hits an object that is BallDestroyer { effectFunc(ballStats); ballStats.SetHitByDestroyer(destroyerIndex); if (!obstacleStats.isPassedThrough) { Destroy(ball); ballList.Remove(ball); // dont forget to remove from the list the empty object } } } }
public double GetAllBallValue() { double value = 0; foreach (var ball in ballList) { BallStats ballStats = ball.GetComponent <BallStats>(); if (ballStats.isUnlocked) { value += ballStats.ballValue / ballStats.spawnTime; } } return(value); }
//Find the closest ball to the jack public int FindClosestBall() { jack = GameObject.FindWithTag("Jack"); ballList.Clear(); foreach (GameObject ball in GameObject.FindGameObjectsWithTag("Ball")) { ballList.Add(ball); } //Declaring variables float shortest = 200; closestBall = gameObject; int player = 0; //Iterate through list foreach (GameObject ball in ballList) { //Calculate distance between current ball and the jack float distance = Vector3.Distance(ball.transform.position, jack.transform.position); //print(ball.ToString() + distance); //If the current ball's distance is lower if (distance < shortest) { //This is the closest ball shortest = distance; closestBall = ball; //get the script for the closest ball BallStats stats = closestBall.GetComponent <BallStats>(); //if the ball was thrown by X player then return that value if (stats.getPlayer() == 1) { player = 1; } else if (stats.getPlayer() == 2) { player = 2; } } //DEBUG Debug.Log("Shortest distance: " + closestBall.ToString() + shortest); } return(player); }
public void SetBall() { BallStats bs = BallStats.balls[ballIndex]; //setting visual sr.sprite = list.spriteList[ballIndex]; tr.startColor = bs.startColor; tr.endColor = bs.endColor; //setting physics rb.mass = bs.mass; rb.gravityScale = bs.gravityScale; maxSpeed = bs.maxSpeed; maxSpin = bs.maxSpin; cc.sharedMaterial.bounciness = bs.bounciness; //TODO: setting particle effect }
void OnTriggerEnter2D(Collider2D collision) { //Debug.Log(collision.tag); if (collision.gameObject == null) { return; } if (collision.tag == "Ball") { ballStats = collision.GetComponent <BallStats>(); if (ballStats.ballColor == this.color) { audioManager.playAudio(ballStats.ballColor.ToString()); gameManager.RemoveActiveBall(collision.gameObject); Destroy(collision.gameObject); } } }
// Start is called before the first frame update void Start() { ballStats = ball.GetComponent <BallStats>(); ChangeBallValueText(); }
// Use this for initialization void Start() { player = GameObject.FindGameObjectWithTag("Player"); ballStats = player.GetComponent <BallStats> (); }
// Update is called once per frame void Update() { if (ballStats.isUnlocked) { timePassed += Time.deltaTime; if (timePassed >= ballStats.spawnTime) // is ready to spawn? { timePassed = 0; Vector3 ballPos = new Vector3(transform.position.x, transform.position.y, ball.transform.position.z); // spawn object as child object of spawner ballList.Add(Instantiate(ball, ballPos, transform.rotation, transform)); // change the position to spawn a little bit off-set of x axis float offset = Random.Range(-3.0f, 3.0f); GameObject ballObj = ballList[ballList.Count - 1]; ballObj.transform.Translate(new Vector3(1.0f, 0f) * offset * Time.deltaTime); } // hit collider if (Input.touchCount > 0) { for (int i = 0; i < Input.touchCount; i++) { // create a raycast //Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position); //Ray ray = new Ray(Input.GetTouch(i).position, Vector3.down); //RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity); Collider2D hit = CameraHelper.GetColliderHit(Input.GetTouch(i).position); for (int j = 0; j < ballList.Count; j++) // loop through each ball { if (hit != null && hit.transform == ballList[j].transform) // if raycast hits an object that is ball { BallStats ballStats = ballList[j].GetComponent <BallStats>(); gameManager.AddMoney(ballStats.ballValue); Destroy(ballList[j]); ballList.Remove(ballList[j]); // dont forget to remove from the list the empty object } } } } //if (Input.GetMouseButtonDown(0)) //{ // // create a raycast // //Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position); // //Ray ray = new Ray(Input.GetTouch(i).position, Vector3.down); // //RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity); // Vector3 wp = Camera.main.ScreenToWorldPoint(Input.mousePosition); // var touchPos = new Vector2(wp.x, wp.y); // Collider2D hit = Physics2D.OverlapPoint(touchPos); // for (int j = 0; j < ballList.Count; j++) // loop through each ball // { // if (hit != null && hit.transform == ballList[j].transform) // if raycast hits an object that is ball // { // BallStats ballStats = ballList[j].GetComponent<BallStats>(); // gameManager.AddMoney(ballStats.ballValue); // Destroy(ballList[j]); // ballList.Remove(ballList[j]); // dont forget to remove from the list the empty object // } // } //} //if (Input.GetMouseButtonDown(0)) //{ // // create a raycast // Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity); // for (int j = 0; j < ballList.Count; j++) // loop through each ball // { // if (hit.collider != null && hit.transform == ballList[j].transform) // if raycast hits an object that is ball // { // BallStats ballStats = ballList[j].GetComponent<BallStats>(); // gameManager.AddMoney(ballStats.ballValue); // Destroy(ballList[j]); // ballList.Remove(ballList[j]); // dont forget to remove from the list the empty object // } // } //} } }
// Start is called before the first frame update void Start() { ballStats = ball.GetComponent <BallStats>(); }
public void ShowData(BallStats ballStats) { distanceText.text = $"Distance: {ballStats.distance:0.0}m"; heightText.text = $"Height: {ballStats.height:0.0}m"; }
protected void AddMoney(BallStats ballStats) { gameManager.AddMoney(ballStats.ballValue * obstacleStats.obstacleValue); }