// Called when the paper hits something! void OnCollisionEnter(Collision collision) { //Debug.Log("ON COLLISION ENTER BABY"); // Always play some audio! this.GetComponent <AudioSource>().Play(); // Only score once per collision; seems dumb, but prevents weird repeat behavior. if (!alreadyScored) { // If you hit a good tag, pop the score prefab right here and inform the GameManager. int pointsScored = 0; switch (collision.gameObject.tag) { case "House": pointsScored = 100; break; case "Person": pointsScored = 500; //Take this opportunity to make the person animate! Animator personAnim = collision.gameObject.GetComponent <Animator>(); personAnim.SetTrigger("OnHit"); break; case "Mailbox": pointsScored = 1000; break; case "Grass": pointsScored = 250; break; } if (pointsScored > 0) { // Pop a nice score object! GameObject scoreObj = (GameObject)GameObject.Instantiate(scorePrefab, collision.transform.position, Camera.main.transform.rotation); ScoreShownOnHit scoreScript = scoreObj.GetComponent <ScoreShownOnHit>(); scoreScript.UpdateTextAndGo("+" + pointsScored); // TODO: Tell the gamemanager! GameManager.instance.score += pointsScored; // Stop this object from scoring again! // But don't delete it, we need that sound effect. alreadyScored = true; } } }
/* * private IEnumerator Wait() * { * yield return new WaitForSeconds(3.0f); * allowedToWave = true; * } */ private void DoWaveFromDirectionVector(Ray originalFamousRay) { // We actually want to do like a ton MORE rays in a box around this one, // and wave at whoever they all hit. Raycasts are cheap! int numRaycastsX = 10; int numRaycastsY = 10; float rayBoxWidth = 5f; float rayBoxHeight = 5f; bool triggeredWave = false; for (int i = 0; i < numRaycastsX; i++) { for (int j = 0; j < numRaycastsY; j++) { // Make it ray Vector3 localDirectionAdjust = new Vector3(-rayBoxWidth / 2f + rayBoxWidth * i / (numRaycastsX - 1), -rayBoxHeight / 2f + rayBoxHeight * j / (numRaycastsY - 1), 0); //Vector3 newOrigin = originalFamousRay.origin + this.transform.TransformDirection(localDirectionAdjust); Vector3 newOrigin = originalFamousRay.origin + localDirectionAdjust; Ray newRay = new Ray(newOrigin, originalFamousRay.direction); RaycastHit hit; float rayDist = 100f; if (!triggeredWave && Physics.Raycast(newRay, out hit, rayDist)) { // Did we hit somebody? If so, it counts as a wave, but only if they're not already waving. if (hit.collider.gameObject.tag == "Person") { Debug.DrawLine(newRay.origin, hit.point, Color.magenta, 4.0f); //Are they waving? Animator personAnim = hit.collider.gameObject.GetComponent <Animator>(); int upperBodyLayer = personAnim.GetLayerIndex("UpperBody"); AnimatorStateInfo currentStateInfo = personAnim.GetCurrentAnimatorStateInfo(upperBodyLayer); bool isWaving = currentStateInfo.IsName("UpperBody.OnWave"); if (!isWaving && !personAnim.GetBool("HasWaved")) { // MAKE 'EM WAVE personAnim.SetTrigger("OnWave"); // Pop a nice score object! GameObject scoreObj = (GameObject)GameObject.Instantiate(scorePrefab, hit.point, Camera.main.transform.rotation); ScoreShownOnHit scoreScript = scoreObj.GetComponent <ScoreShownOnHit>(); scoreScript.UpdateTextAndGo("+1000"); // TODO: Tell the gamemanager! GameManager.instance.score += 1000; //TODO: check if male or female voice.GetComponent <PeopleSpeach>().PlayVoice(); //allowedToWave = false; //StartCoroutine(Wait()); triggeredWave = true; personAnim.SetBool("HasWaved", true); } } } else { // No hit, but pretty editor line Debug.DrawLine(newRay.origin, newRay.origin + newRay.direction * rayDist, Color.white, 4.0f); } } } }