private void Shoot() { int layerMask = 1 << 8; layerMask = ~layerMask; CameraSound.PlayShoot(arrowFlySound); RaycastHit hit; Physics.Raycast(mainCamera.position, mainCamera.TransformDirection(Vector3.forward), out hit, 1000, layerMask); if (hit.collider) { shootTarget.position = hit.point; } else { shootTarget.position = mainCamera.TransformDirection(Vector3.forward * 10000); } Debug.Log(hit.collider); GameObject arrow = Instantiate(arrowPrefab, bowInHand.transform.position, Quaternion.identity); arrow.transform.SetParent(null); arrow.transform.LookAt(shootTarget); arrow.GetComponent <Rigidbody>().AddRelativeForce(arrow.transform.forward * shootForce, ForceMode.Impulse); }
void CollectHarvest(HarvestResult harvestResult) { if (!harvestResult.success) { if (_harvesting) { _harvesting = false; _behaviour.canMove = true; } _onHarvestEnd(false); return; } if (_inventory) { if (_harvesting) { _harvesting = false; _behaviour.canMove = true; } CameraSound.PlaySoundAtCameraPosition(harvestSound, 0.5f); _inventory.AddItem(harvestResult.harvest); _onHarvestEnd(true); } else { _onHarvestEnd(false); } }
public void ConsumeFuel(int amount) { if (_inventory.SubtractFuel(amount)) { CameraSound.PlaySoundAtCameraPosition(eatSound, 0.3f); _fuelTimer.AddTime(amount * timerPerFuel); } }
private void Start() { cmra = transform.Find("Vision").GetComponent <CameraDetect>(); vision = cmra.gameObject.GetComponent <SpriteRenderer>(); soundSource = GetComponent <CameraSound>(); security.SetLaserColor(linkCode, indic); }
void ShowHappy() { if (!_showingEmotion) { _showingEmotion = true; CameraSound.PlaySoundAtCameraPosition(happySound, 0.5f); emotionAnimator.SetTrigger(IsHappy); StartCoroutine(FinishShowingEmotion()); } }
private void Update() { if (CrossPlatformInputManager.GetButtonDown("BowGet")) { SwapBow(); } if (Input.GetKeyDown(KeyCode.C)) { if (animator.GetBool("Crouching")) { animator.SetBool("Crouching", false); } else { animator.SetBool("Crouching", true); } } if (animator.GetBool("Crouching")) { float h = CrossPlatformInputManager.GetAxis("Horizontal"); float v = CrossPlatformInputManager.GetAxis("Vertical"); animator.SetFloat("Forward", v, 0.1f, Time.deltaTime); animator.SetFloat("Turn", h, 0.1f, Time.deltaTime); if (v < 0) { transform.position += Vector3.forward * backwardSpeed * v * Time.deltaTime; } else { transform.position += Vector3.forward * forwardSpeed * v * Time.deltaTime; } transform.position += Vector3.right * sideSpeed * h * Time.deltaTime; } else { float h = CrossPlatformInputManager.GetAxis("Horizontal"); float v = CrossPlatformInputManager.GetAxis("Vertical"); float aimButton = CrossPlatformInputManager.GetAxis("Aim"); if (aimButton == 1) { animator.SetBool("Aim", true); iK.enabled = true; if (!bowInHand.activeSelf) { bowInHand.SetActive(true); bowOnBack.SetActive(false); } } else { animator.SetBool("Aim", false); animator.SetBool("Overdraw", false); iK.enabled = false; } Debug.Log(aimButton); animator.SetFloat("Forward", v, 0.1f, Time.deltaTime); animator.SetFloat("Turn", h, 0.1f, Time.deltaTime); if (!animator.GetBool("Aim")) { transform.localEulerAngles += new Vector3(transform.localEulerAngles.x, h * rotationSpeed, transform.localEulerAngles.z); } float h2 = CrossPlatformInputManager.GetAxis("Horizontal2"); float v2 = CrossPlatformInputManager.GetAxis("Vertical2"); cameraPosition.eulerAngles += new Vector3(v2 * rotationSpeed, h2 * rotationSpeed, 0); if (h2 != 0 && v > 0.1f) { transform.localEulerAngles += new Vector3(transform.localEulerAngles.x, h2 * rotationSpeed, transform.localEulerAngles.z); } if (rb.velocity.y < -1f) { animator.SetTrigger("Falling"); } if (animator.GetBool("Aim")) { spine.localEulerAngles += new Vector3(spine.localEulerAngles.x, 2, spine.localEulerAngles.y); } bool overdrawButton = CrossPlatformInputManager.GetButtonDown("Overdraw"); if (overdrawButton && animator.GetBool("Aim")) { animator.SetBool("Overdraw", true); CameraSound.PlayShoot(bowStrenghtSound); } bool overdrawButtonUp = CrossPlatformInputManager.GetButtonUp("Overdraw"); if (overdrawButtonUp && animator.GetBool("Aim")) { animator.SetTrigger("Shoot"); //Shoot(); animator.SetBool("Overdraw", false); } } Vector3 MousePos = Input.mousePosition; DebugRaycast(); }