public hoopObject() { getNextHoopPos(); material = new Hoop(5f, 7f, 1f, 10); addBehavior(new hoopControl()); addBehavior(new hoopLogic()); }
/// Update the nearest hoop to the agent private void UpdateNearestHoop() { foreach (GameObject hoop in hoopArea.hoops) { if (nearestHoop == null && hoop != null) { // No current nearest hoop, so set to this hoop nearestHoop = hoop; nearestHoopScript = nearestHoop.GetComponent <Hoop>(); } else if (hoop != null) { // Calculate distance to this hoop and distance to the current nearest hoop float distanceToFlower = Vector3.Distance(hoop.transform.position, witchTransform.position); float distanceToCurrentNearestFlower = Vector3.Distance(nearestHoop.transform.position, witchTransform.position); // If current nearest hoop is empty OR this flower is hoop, update the nearest flower if (nearestHoop == null || distanceToFlower < distanceToCurrentNearestFlower) { nearestHoop = hoop; nearestHoopScript = nearestHoop.GetComponent <Hoop>(); } } } }
bool CheckIfScored() { Hoop hoop = FindObjectOfType <Hoop>(); if (Utils.GetDistance(current_tile.position, hoop.current_tile.position) <= 1) { if (GetComponent <TutorialPlayer>() == null) { FindObjectOfType <ScoreCounter>().PlayerScored(this); } FindObjectOfType <DunkBannerMove>().Dunk(this); canvas.transform.Find("Command Window").GetComponent <CommandWindow>().Cancel(); GetComponentInChildren <Ball>().gameObject.SetActive(false); StopAllCoroutines(); Utils.SetDunkAnimation(); Invoke("DelayChange", 3.5f); return(true); } else { return(false); } }
public void RemoveHoop(Hoop hoop) { hoop.shouldEject = false; if (hoops.Contains(hoop)) { hoops.Remove(hoop); } }
void CheckIfScored() { Hoop hoop = FindObjectOfType <Hoop>(); if (Utils.GetDistance(current_tile.position, hoop.current_tile.position) <= 1) { FindObjectOfType <ScoreCounter>().PlayerScored(this); Invoke("DelayChange", 0.5f); } }
public void SpawnPlayer2() { GameObject go = Instantiate(netPrefab, spawnPoint.position, Quaternion.identity); go.transform.localScale = new Vector3(-1, 1, 1); Hoop hoopManager = go.GetComponentInChildren <Hoop>(); hoopManager.SetPlayerIndex(2); }
public void AddHoop(Hoop hoop) { if (hoops.Count > 0 && hoops[hoops.Count - 1].hoopSize < hoop.hoopSize) { hoop.shouldEject = true; } else { if (!hoops.Contains(hoop)) { hoops.Add(hoop); } } }
void OnTriggerEnter2D(Collider2D other) { if (other.transform.parent) { Hoop hoop = other.transform.parent.GetComponent <Hoop>(); if (hoop) { Vector3 toHoop = hoop.scoreTransform.position - transform.position; if (Vector3.Dot(toHoop, Vector3.down) > 0f) { hoop.Score(); } } } }
private void OnPlayerScored(Hoop hoop) { int index = hoops.IndexOf(hoop); scores[index]++; ScoreChanged?.Invoke(index, scores[index]); particles.ForEach(ps => ps.Play()); cameraShake.ShakeCamera(shakeIntensity, shakeDuration); if (scores[index] >= maxScore) { GameEnded?.Invoke(index); } }
// Update is called once per frame void Update() { if (ball.position.x > transform.position.x + passedRange) { GameManager.instance.SetGameOver(); } if (!hasSpawned && ball.position.x > transform.position.x + spawnRange) { GameObject spawn = Instantiate(gameObject); spawn.GetComponent <PositionOnScreen>().enabled = false; spawn.transform.position = new Vector3(transform.position.x + 5f, Random.Range(-2, 2), 0f); spawnHoop = spawn.GetComponent <Hoop>(); spawnHoop.index = index + 1; spawn.name = "Spawn" + spawnHoop.index; hasSpawned = true; } }
void Awake() { hoop = transform.parent.gameObject.GetComponent<Hoop>(); }
/// Move the agent to a safe random position (i.e. does not collide with anything) /// If in front of hoop, also point the agent at the hoop /// inFrontOfFHoop - whether to choose a spot in front of a hoop private void MoveToSafeRandomPosition(bool inFrontOfFHoop) { bool safePositionFound = false; int attemptsRemaining = 200; // Prevent an infinite loop Vector3 potentialPosition = Vector3.zero; Quaternion potentialRotation = new Quaternion(); // Loop until a safe position is found or we run out of attempts while (!safePositionFound && attemptsRemaining > 0) { attemptsRemaining--; if (inFrontOfFHoop) { // Pick a random hoop GameObject randomHoop = hoopArea.hoops[UnityEngine.Random.Range(0, hoopArea.hoops.Count)]; Hoop randomHoopScript = randomHoop.GetComponent <Hoop>(); // Position 30 to 40 cm in front of the hoop float distanceFromFlower = UnityEngine.Random.Range(.3f, .4f); potentialPosition = randomHoop.transform.position + randomHoopScript.HoopUpVector * distanceFromFlower; // Point agent at hoop Vector3 toHoop = randomHoopScript.RingCenterPosition - potentialPosition; potentialRotation = Quaternion.LookRotation(toHoop, Vector3.up); } else { // Pick a random height from the ground float height = UnityEngine.Random.Range(1.2f, 2.5f); // Pick a random radius from the center of the area float radius = UnityEngine.Random.Range(2f, 7f); // Pick a random direction rotated around the y axis Quaternion direction = Quaternion.Euler(0f, UnityEngine.Random.Range(-180f, 180f), 0f); // Combine height, radius, and direction to pick a potential position potentialPosition = hoopArea.transform.position + Vector3.up * height + direction * Vector3.forward * radius; // Choose and set random starting pitch and yaw float pitch = UnityEngine.Random.Range(-60f, 60f); float yaw = UnityEngine.Random.Range(-180f, 180f); potentialRotation = Quaternion.Euler(pitch, yaw, 0f); } // Check to see if the agent will collide with anything Collider[] colliders = Physics.OverlapSphere(potentialPosition, 0.05f); // Safe position has been found if only one collider overlapped safePositionFound = colliders.Length == 1; //if statemate that is only active in training mode, used for recording the last known position to a hoop if (trainingMode) { lastDistanceToHoop = Vector3.Distance(transform.position, nearestHoop.transform.position); } } //If the loop is unable to find a safe space to spawn based on the collider check, exit the loop Debug.Assert(safePositionFound, "Could not find a safe position to spawn"); // Set the position and rotation transform.position = potentialPosition; transform.rotation = potentialRotation; }
private void CreateHoop() { if (hoop != null) { Destroy(hoop.gameObject); } // Create sceneObject string hPath = "Prefabs/Hoop"; GameObject go = Instantiate(Resources.Load(hPath), Vector3.zero, Quaternion.identity) as GameObject; hoop = go.GetComponent<Hoop>() as Hoop; if (hoop != null) { float dist1 = float.MinValue; float dist2 = float.MinValue; Vector3 pos = Vector3.zero; Quaternion rot = Quaternion.identity; // Make sure the hoop is some distance away from the object and target while (dist1 < 10f || dist2 < 10f) { // Give it a random position and orientation. pos = new Vector3(UnityEngine.Random.Range(-20f, 20f), UnityEngine.Random.Range( 2f, 20f), UnityEngine.Random.Range( 7f, 23f)); rot = UnityEngine.Random.rotation; float dx1 = pos.x - sceneObject.transform.position.x; float dy1 = pos.y - sceneObject.transform.position.y; float dz1 = pos.z - sceneObject.transform.position.z; dist1 = Mathf.Sqrt(dx1 * dx1 + dy1 * dy1 + dz1 * dz1); float dx2 = pos.x - sceneTarget.transform.position.x; float dy2 = pos.y - sceneTarget.transform.position.y; float dz2 = pos.z - sceneTarget.transform.position.z; dist2 = Mathf.Sqrt(dx2 * dx2 + dy2 * dy2 + dz2 * dz2); } hoop.transform.position = pos; hoop.transform.rotation = rot; } }
public override void OnDestory() { hoop = null; base.OnDestory(); }
public override void Start() { base.Start(); hoop = (((obj) as GameObject3d).material as Hoop); }