// Start is called before the first frame update void Start() { goldManager = goldManagerObject.GetComponent <Gold_Manager>(); fishingRod = fishingRodObject.GetComponent <FishingRod>(); goldAmt = GameObject.Find("Current Gold").GetComponent <Text>(); upgradeButtons = new Button[] { rodButton.GetComponent <Button>(), lineButton.GetComponent <Button>(), hookButton.GetComponent <Button>(), lureButton.GetComponent <Button>() }; upgradeCosts = new Text[] { rodButton.transform.Find("cost").GetComponent <Text>(), lineButton.transform.Find("cost").GetComponent <Text>(), hookButton.transform.Find("cost").GetComponent <Text>(), lureButton.transform.Find("cost").GetComponent <Text>() }; for (int i = 0; i < upgradeCosts.Length; i++) { upgradeCosts[i].text = $"${UpgradeLevels.GetUpgrade((UpgradeLevels.Types)i, upgradeIndices[i]).cost}"; } }
// Start is called before the first frame update void Start() { fishPosition = transform.position; spriteRenderer = gameObject.GetComponent <SpriteRenderer>(); fishingRod = GameObject.Find("fishing_pole").GetComponent <FishingRod>(); fishSpeed = Random.Range(1.5f, 2.5f); // determines the random weight of the given fish //fishForGold = gameObject.GetComponent<Fish>(); fishWeight = RandomWeight(fishForGold.type); // determines the gold of this fish goldManager = GameObject.Find("MrManager").GetComponent <Gold_Manager>(); //gold = goldManager.ReturnGoldByWeight(fishForGold.type, fishWeight); // Set the reference points depending on the fish's movement pattern referencePoints = new List <Vector2>(); switch (movementPattern) { case MovementPattern.LeftRight: // Gets a reference to the left and right positions of the screen if (referencePoints.Count == 0) { referencePoints.Insert(0, fishPosition + new Vector2(-8.0f, 0)); referencePoints.Insert(1, fishPosition + new Vector2(8.0f, 0)); } // Start with a random position on the pattern patternInt = Random.Range(0, referencePoints.Count); fishPosition = Vector2.Lerp(referencePoints[patternInt], referencePoints[(patternInt + 1) % referencePoints.Count], Random.Range(0.0f, 1.0f)); UpdateTransformPosition(); break; case MovementPattern.CircleCW: // Generates a clockwise circle of reference points around the fish's current position if (referencePoints.Count == 0) { float referencePointRadius = Random.Range(0.8f, 1.2f); // Must be a radius of at least 0.2f referencePoints.Insert(0, fishPosition + referencePointRadius * new Vector2(0.000f, 1.000f)); referencePoints.Insert(1, fishPosition + referencePointRadius * new Vector2(0.259f, 0.969f)); referencePoints.Insert(2, fishPosition + referencePointRadius * new Vector2(0.500f, 0.866f)); referencePoints.Insert(3, fishPosition + referencePointRadius * new Vector2(0.707f, 0.707f)); referencePoints.Insert(4, fishPosition + referencePointRadius * new Vector2(0.866f, 0.500f)); referencePoints.Insert(5, fishPosition + referencePointRadius * new Vector2(0.969f, 0.259f)); referencePoints.Insert(6, fishPosition + referencePointRadius * new Vector2(1.000f, 0.000f)); referencePoints.Insert(7, fishPosition + referencePointRadius * new Vector2(0.969f, -0.259f)); referencePoints.Insert(8, fishPosition + referencePointRadius * new Vector2(0.866f, -0.500f)); referencePoints.Insert(9, fishPosition + referencePointRadius * new Vector2(0.707f, -0.707f)); referencePoints.Insert(10, fishPosition + referencePointRadius * new Vector2(0.500f, -0.866f)); referencePoints.Insert(11, fishPosition + referencePointRadius * new Vector2(0.259f, -0.969f)); referencePoints.Insert(12, fishPosition + referencePointRadius * new Vector2(0.000f, -1.000f)); referencePoints.Insert(13, fishPosition + referencePointRadius * new Vector2(-0.259f, -0.969f)); referencePoints.Insert(14, fishPosition + referencePointRadius * new Vector2(-0.500f, -0.866f)); referencePoints.Insert(15, fishPosition + referencePointRadius * new Vector2(-0.707f, -0.707f)); referencePoints.Insert(16, fishPosition + referencePointRadius * new Vector2(-0.866f, -0.500f)); referencePoints.Insert(17, fishPosition + referencePointRadius * new Vector2(-0.969f, -0.259f)); referencePoints.Insert(18, fishPosition + referencePointRadius * new Vector2(-1.000f, 0.000f)); referencePoints.Insert(19, fishPosition + referencePointRadius * new Vector2(-0.969f, 0.259f)); referencePoints.Insert(20, fishPosition + referencePointRadius * new Vector2(-0.866f, 0.500f)); referencePoints.Insert(21, fishPosition + referencePointRadius * new Vector2(-0.707f, 0.707f)); referencePoints.Insert(22, fishPosition + referencePointRadius * new Vector2(-0.500f, 0.866f)); referencePoints.Insert(23, fishPosition + referencePointRadius * new Vector2(-0.259f, 0.969f)); } // Start with a random position on the pattern patternInt = Random.Range(0, referencePoints.Count); fishPosition = Vector2.Lerp(referencePoints[patternInt], referencePoints[(patternInt + 1) % referencePoints.Count], Random.Range(0.0f, 1.0f)); UpdateTransformPosition(); break; case MovementPattern.CircleCCW: // Generates a counterclockwise circle of reference points around the fish's current position if (referencePoints.Count == 0) { float referencePointRadius = Random.Range(0.8f, 1.2f); // Must be a radius of at least 0.2f referencePoints.Insert(0, fishPosition + referencePointRadius * new Vector2(0.000f, 1.000f)); referencePoints.Insert(1, fishPosition + referencePointRadius * new Vector2(-0.259f, 0.969f)); referencePoints.Insert(2, fishPosition + referencePointRadius * new Vector2(-0.500f, 0.866f)); referencePoints.Insert(3, fishPosition + referencePointRadius * new Vector2(-0.707f, 0.707f)); referencePoints.Insert(4, fishPosition + referencePointRadius * new Vector2(-0.866f, 0.500f)); referencePoints.Insert(5, fishPosition + referencePointRadius * new Vector2(-0.969f, 0.259f)); referencePoints.Insert(6, fishPosition + referencePointRadius * new Vector2(-1.000f, 0.000f)); referencePoints.Insert(7, fishPosition + referencePointRadius * new Vector2(-0.969f, -0.259f)); referencePoints.Insert(8, fishPosition + referencePointRadius * new Vector2(-0.866f, -0.500f)); referencePoints.Insert(9, fishPosition + referencePointRadius * new Vector2(-0.707f, -0.707f)); referencePoints.Insert(10, fishPosition + referencePointRadius * new Vector2(-0.500f, -0.866f)); referencePoints.Insert(11, fishPosition + referencePointRadius * new Vector2(-0.259f, -0.969f)); referencePoints.Insert(12, fishPosition + referencePointRadius * new Vector2(0.000f, -1.000f)); referencePoints.Insert(13, fishPosition + referencePointRadius * new Vector2(0.259f, -0.969f)); referencePoints.Insert(14, fishPosition + referencePointRadius * new Vector2(0.500f, -0.866f)); referencePoints.Insert(15, fishPosition + referencePointRadius * new Vector2(0.707f, -0.707f)); referencePoints.Insert(16, fishPosition + referencePointRadius * new Vector2(0.866f, -0.500f)); referencePoints.Insert(17, fishPosition + referencePointRadius * new Vector2(0.969f, -0.259f)); referencePoints.Insert(18, fishPosition + referencePointRadius * new Vector2(1.000f, 0.000f)); referencePoints.Insert(19, fishPosition + referencePointRadius * new Vector2(0.969f, 0.259f)); referencePoints.Insert(20, fishPosition + referencePointRadius * new Vector2(0.866f, 0.500f)); referencePoints.Insert(21, fishPosition + referencePointRadius * new Vector2(0.707f, 0.707f)); referencePoints.Insert(22, fishPosition + referencePointRadius * new Vector2(0.500f, 0.866f)); referencePoints.Insert(23, fishPosition + referencePointRadius * new Vector2(0.259f, 0.969f)); } // Start with a random position on the pattern patternInt = Random.Range(0, referencePoints.Count); fishPosition = Vector2.Lerp(referencePoints[patternInt], referencePoints[(patternInt + 1) % referencePoints.Count], Random.Range(0.0f, 1.0f)); UpdateTransformPosition(); break; case MovementPattern.Wander: // Sets the min/max wander boundaries if (referencePoints.Count == 0) { referencePoints.Insert(0, fishPosition + new Vector2(-4.0f, -2.0f)); referencePoints.Insert(1, fishPosition + new Vector2(4.0f, 2.0f)); } // Start with a random location within the assigned boundaries fishPosition = new Vector2( Random.Range(referencePoints[0].x, referencePoints[1].x), Random.Range(referencePoints[0].y, referencePoints[1].y) ); // Place the objective on top of the fish so it chooses a new wander point objective to start patternTimer = 0.0f; currentObjective = fishPosition; UpdateTransformPosition(); break; default: break; } movementPatternOrig = movementPattern; UpdateDirectionAndSpeed(); fishingRod.oceanFish.Add(gameObject); }