// Update is called once per frame void Update() { Vector3 screenCenter = new Vector3(cam.pixelWidth / 2, cam.pixelHeight / 2, 0); Ray ray = cam.ScreenPointToRay(screenCenter); RaycastHit hit; //Debug.DrawRay (ray.origin, ray.direction *10, Color.yellow, 2); if (Input.GetMouseButton(0)) { if (Physics.Raycast(ray, out hit)) { //check if raycast hits enemy GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget> (); if (target != null) { Debug.Log("target hit"); target.ReactToHit(); } else { //Debug.Log (hit.point); //Display a sphere at hit point then destroy the sphere StartCoroutine(SphereIndicator(hit.point)); } } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0) && currentAmmo > 0) { soundSource.PlayOneShot(hitEnemy); Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; currentAmmo--; ammoCount.text = currentAmmo + "/" + maxAmmo; if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); if (target != null) { target.ReactToHit(); } } else { StartCoroutine(SphereIndicator(hit.point)); } } if (Input.GetKey("r") && (currentAmmo < maxAmmo || currentAmmo == 0)) { StartCoroutine(ReloadWeapon()); } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { Vector3 point = new Vector3(_camera.pixelWidth * 0.5f, _camera.pixelHeight * 0.5f, 0); Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { //Debug.Log("Hit " + hit.point); GameObject hitObj = hit.transform.gameObject; ReactiveTarget target = hitObj.GetComponent <ReactiveTarget>(); if (target != null) { //Debug.Log("target hit"); target.ReactToHit(); Messenger.Broadcast(GameEvent.ENEMY_HIT); } else { StartCoroutine(ShpereIndicator(hit.point)); } } } }
// Update is called once per frame void Update() { if (Input.GetMouseButton(0)) { Vector3 point = new Vector3(cam.pixelWidth / 2, cam.pixelHeight / 2, 0); Ray ray = cam.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitOBJ = hit.transform.gameObject; Debug.DrawLine(ray.origin, hit.point, Color.red, 1); if (hitOBJ.GetComponent <enablePhysics>()) { hitOBJ.GetComponent <enablePhysics>().EnableHit(); } else if (hitOBJ.GetComponent <Destruction>()) { hitOBJ.GetComponent <Destruction>().OnHit(); } ReactiveTarget target = hitOBJ.GetComponent <ReactiveTarget>(); if (target != null) { target.ReactToHit(); Debug.Log("Hit Reactive Target"); } else { // StartCoroutine(SphereIndicator(hit.point)); Debug.Log("Hit " + hit.point); } } } }
void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 point = new Vector3(playerCamera.pixelWidth / 2, playerCamera.pixelHeight / 2, 0); //get screen centre Ray ray = playerCamera.ScreenPointToRay(point); //create ray at screen centre RaycastHit hit; if (Physics.Raycast(ray, out hit)) //out is c# syntax that ensures hit is passed directly into the method rather than as a copy { GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); fireball = Instantiate(fireballPrefab) as GameObject; fireball.transform.position = transform.TransformPoint(Vector3.forward * 2f); //place fireball in front of shooter fireball.transform.rotation = transform.rotation; //point fireball in same direction if (target != null) { target.ReactToHit(); } } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); // Center of screen is half the widith and half the height Ray ray = _camera.ScreenPointToRay(point); // Create a ray RaycastHit hit; // Used to store reference to the object that the ray may hit if (Physics.Raycast(ray, out hit)) // Check if and get what the ray hit { Debug.Log("Hit " + hit.point); GameObject hitObject = hit.transform.gameObject; // Retrieve the object the ray hit ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); if (target != null) // If it is a enemy then do the enemy reaction function { Debug.Log("Target Hit"); target.ReactToHit(); Messenger.Broadcast(GameEvent.ENEMY_HIT); } else // else just show where you raycasted { StartCoroutine(SphereIndicator(hit.point)); // call coroutine } } } }
// Update is called once per frame void Update() { if (allowRayShooting && Input.GetMouseButtonDown(0)) { Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); if (target) { target.ReactToHit(); } else { StartCoroutine(SphereIndiacator(hit.point)); } } } if (Input.GetKeyDown(KeyCode.Escape)) { // Unlock cursor on Esc press Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); if (target != null) { int i; for (i = 0; i < 3; i++) { _colors[i] = _images[i].color; } Color color = FindColor(); _score += target.ReactToHit(color); textScore.text = "Score : " + _score; } else { Color color = FindColor(); StartCoroutine(SphereIndicator(hit.point, color)); } } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0) && !(EventSystem.current.IsPointerOverGameObject())) { Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { // get component transform from object dat we hit GameObject hitObject = hit.transform.gameObject; // try get component ReactiveTarget, // if this script is attach to object, then object is active ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); if (target != null) { target.ReactToHit(); // broadvast messge when hit block. Display will receive this messge and show enw result Messenger.Broadcast(GameEvent.ENEMY_HIT); } else { StartCoroutine(SphereIndicator(hit.point)); } } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { Vector3 point = new Vector3(_camera.pixelWidth / 2f, _camera.pixelHeight / 2f, 0); Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); if (target != null) { target.ReactToHit(); _soundSource.PlayOneShot(_hitEnemySound); Messenger.Broadcast(GameEvent.EnemyHit); } else { StartCoroutine(SphereIndicator(hit.point)); _soundSource.PlayOneShot(_hitWallSound); } } } }
// Update is called once per frame void Update() { if (Input.GetMouseButton(0)) { Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); //getting the middle of the screen Ray ray = _camera.ScreenPointToRay(point); //creates a ray at a position, specifically the position we just defined RaycastHit hit; if (Physics.Raycast(ray, out hit)) // out modifier puts information into the variable hit (not exactly what it does but it does tahat in this context) { GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); if (target != null) { Debug.Log("Hit Enemy"); target.ReactToHit(); } else { //Debug.Log("Hit " + hit.point); StartCoroutine(SphereIndicator(hit.point)); //a coroutine is essentially like a thread, enables us to run multiple functions at once and pause one without pausing others } } } }
// Update is called once per frame void Update() { // Check that we aren't clicking on a GUI object (prevent shooting while interacting with GUI) if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { Vector3 screenCenterPoint = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2); // create ray from center of the camera screen Ray ray = _camera.ScreenPointToRay(screenCenterPoint); RaycastHit hit; // RaycastHit data structure stores information about the intersection of the ray // Needs Physics.Raycast() to mutate data on where the intersection happened and which object was intersected // the out in the argument is like C++ passing in by reference, as opposed to copying it into scope? if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; // retrieve the object that ray hit ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); // This is because we created our own C# ReactiveTarget script // this method checks that the object has this Component/Script attached to it, else returns null // elif / switch issues come to mind when you have multiple script detection (probably has an elegant design pattern to solve this) // we could also do hitObject.GetComponent<KeyboardMovement> or GetComponent<MouseLook> which was done in Section 2 if (target != null) { Debug.Log("Target Hit: " + hit.point); target.ReactToHit(); // calling method on the target, which we need to define in <ReactiveTarget> script Messenger.Broadcast(GameEvent.ENEMY_HIT); // broadcast } else { StartCoroutine(ShowHitLocationUsingSphere(hit.point)); } } // else if Physics.Raycast returns false, it didn't hit any object (e.g. it hit the "sky") } }
// Update is called once per frame void Update() { // проверяем что GUI не используется if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) //реакция на нажатие кнопки мыши { //середина экрана это половина его ширины и высоты Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); //создание в этой точке луча Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; //инфа о пересечении лучаб о точке где возник луч и об объекте с кот.столкнулся //испущенный луч заполняет информацией переменную, на которую имеется ссылка if (Physics.Raycast(ray, out hit)) //возвращает true если луч столкнулся { //Debug.Log("Hit " + hit.point); //загружаем коордтнаты точки, в которую попал луч GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); if (target != null) { //Debug.Log("Target hit"); target.ReactToHit(); soundSource.PlayOneShot(hitEnemySound); //soundSource.clip = hitEnemySound; soundSource.Play(); //в этом случае звуки перекрывают друг друга } else { StartCoroutine(SphereIndicator(hit.point)); } soundSource.PlayOneShot(hitWallSound); } } }
/// <summary> /// Shoot bullet upon left mouse click, play specific FX depending on target hit /// Crawler will reach to hit if shot by the bullet /// Gun bullet is drawn if hit anything else except the crawler /// </summary> void Update() { if (!EventSystem.current.IsPointerOverGameObject()) { if (canShoot && Input.GetMouseButtonDown(0)) { Vector3 point = new Vector3(mainCamera.pixelWidth / 2, mainCamera.pixelHeight / 2, 0); Ray ray = mainCamera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); if (target != null) { audioSource.PlayOneShot(shotCrawler); target.ReactToHit(); } else { audioSource.PlayOneShot(bulletThud); StartCoroutine(GunBullet(hit.point)); } } } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); Ray ray = _camera.ScreenPointToRay(point); RaycastHit hitObject; if (Physics.Raycast(ray, out hitObject)) { GameObject hitGameObject = hitObject.transform.gameObject; ReactiveTarget targetScript = hitGameObject.GetComponent <ReactiveTarget>(); // If the target in front of you is not null, then do action... if (targetScript != null) { Debug.Log("Hit target"); // Custom scripted behavior that is created in ReactiveTarget class targetScript.ReactToHit(); } // If the target in front of you is null, then just create a sphere... else { Vector3 pos = hitObject.point; StartCoroutine(SphereIndicator(pos)); } } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { Vector3 point = new Vector3( _camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; //получем объект, в который попал луч ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); if (target != null) //проверяем наличие у этого объекта компонента ReactiveTarget { // Debug.Log("Target Hit"); target.ReactToHit(); //Вызов метода для мишени Messenger.Broadcast(GameEvent.ENEMY_HIT); //рассылка сообщения } else { //Вызов попрограммы для создания сферы в месте попадания StartCoroutine(SphereIndicator(hit.point)); } } } }
void Update() { // реагируем на нажатие кнопки мыши if (Input.GetMouseButtonDown(0)) { // создаем луч из камеры идущий от центра экрана Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); Ray ray = _camera.ScreenPointToRay(point); //создаем структуру с данными о пересеченном объекте RaycastHit hit; // пускаем луч по прямой if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; switch (hitObject.tag) { case "Enemy": // если враг то наносим урон ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); target.ReactToHit(); break; default: // иначе создаем след от выстрела StartCoroutine(SphereIndikaor(hit.point)); break; } } } }
void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); if (target != null) { interfacePlayer.AddScore(); //target.AddScore(); target.ReactToHit(); //Messenger.Broadcast(GameEvent.ENEMY_HIT); } else { StartCoroutine(SphereIndicator(hit.point)); } } } }
private void shoot() { // Ray ray = _camera.ScreenPointToRay(point); timer = 0f; ray.origin = transform.position; ray.direction = transform.forward; laserline.enabled = true; laserline.SetPosition(0, transform.position); Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2); RaycastHit hit; if (Physics.Raycast(ray, out hit, obstacleRange)) { GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); soundSource.PlayOneShot(laser); laserline.SetPosition(1, hit.point); if (target != null) { target.ReactToHit(); killcount += 1; } } }
void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); if (target != null) { target.ReactToHit(); soundSource.PlayOneShot(hitEnemySound); /*soundSource.clip = hitEnemySound; * soundSource.Play();*/ } else { StartCoroutine(SphereIndicator(hit.point)); soundSource.PlayOneShot(hitWallSound); } } } }
// Update is called once per frame void Update() { //Check the 'missle#Fired' tag from the fireMissle method. // If the missle has been fired, transform its position // forward * the rocketSpeed, and sync it with deltaTime. if (missle2Fired) { missleSalvo[2].transform.position += missleSalvo[2].transform.forward * rocketSpeed * Time.deltaTime; Debug.Log("Missle 3 changing direction"); } if (missle1Fired) { missleSalvo[1].transform.position += missleSalvo[1].transform.forward * rocketSpeed * Time.deltaTime; Debug.Log("Missle 2 changing direction"); } if (missle0Fired) { missleSalvo[0].transform.position += missleSalvo[0].transform.forward * rocketSpeed * Time.deltaTime; Debug.Log("Missle 1 changing direction"); } if (Input.GetButtonDown("Fire1Player2")) { Debug.Log("Shoot Button Pressed"); fireMissle(); Debug.Log("FireMissle executed"); //GameObject missle = Instantiate (_misslePrefab, this.transform.position, this.transform.rotation) as GameObject; //missle.GetComponent<Rigidbody> ().velocity = transform.forward; //missle.transform.Translate (Vector3.forward * Time.deltaTime); //Debug.Log ("P2 -- Point pos: " + point.ToString()); //Debug.Log ("P2 -- Angles: " + rotatePoint.ToString ()); //Debug.Log ("Missle Coords: " + missle.transform.position.ToString () + " | Angles: " + missle.transform.rotation.ToString ()); //Ray casting code i dont quite understand - should figure it out Vector3 point = _player.transform.position; Ray ray = new Ray(point, transform.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget> (); // is this our enemy? if (target != null) { target.ReactToHit(); } else { //visually indicate where hit StartCoroutine(SphereIndicator(hit.point)); } } } }
// Update is called once per frame void Update() { // Respond to mouse click. if (Input.GetMouseButtonDown(0)) { // Middle of screen is half its width and height. Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); // Create a ray from camera to screen point. Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { // The GameObject that was hit. GameObject hitObject = hit.transform.gameObject; // ReactiveTarget script component on the object. ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); if (target != null) { // GameObject with ReactiveTarget component was hit. Call a method of the // target instead of just emitting a debug message. target.ReactToHit(); } else { // Something else was hit. // Launch non-blocking coroutine to show a sphere where ray hit something. StartCoroutine(SphereIndicator(hit.point)); } } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { Vector3 shootPoint = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); // Vector3 shootPoint = new Vector3(Input.GetAxis("Mouse X"),Input.GetAxis("Mouse Y"),0); Ray ray = _camera.ScreenPointToRay(shootPoint); //from the Screen Coordinate to the global Coordinate RaycastHit hit; if (Physics.Raycast(ray, out hit)) { // Debug.Log ("Hit " + hit.point); //Coroutines are a Unity-specific way of handling tasks that execute incrementally over time, //as opposed to how most functions make the program wait until they finish GameObject hitObject = hit.transform.gameObject; ReactiveTarget reactiveTarget = hitObject.GetComponent <ReactiveTarget> (); if (reactiveTarget != null) { // Debug.Log ("hit target"); reactiveTarget.ReactToHit(); Messenger.Broadcast(GameEvent.ENEMY_HIT); soundSource.PlayOneShot(hitEnermySound); //soundSource.clip = hitEnermySound; //soundSource.Play(); } else { StartCoroutine(SphereIndicator(hit.point)); soundSource.PlayOneShot(hitWallSound); } } } }
void Update() { // enables or disables mouse lock and visibility also pauses game if mouse is visible if (Input.GetKeyDown(KeyCode.Alpha1)) { if (Cursor.visible == true) { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; Time.timeScale = 1f; settingsPopUp.Close(); } else { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; Time.timeScale = 0f; settingsPopUp.Open(); } } // enables shooing only if game isnt paused if (Time.timeScale != 0) { if ((Input.GetKeyDown(KeyCode.RightControl)) && (!EventSystem.current.IsPointerOverGameObject())) { // this creates a vector with the coridnates of the rays origin Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); muzzleFlash.Play(); gunShot.Play(); // creates ray object with origin cordinates Ray ray = _camera.ScreenPointToRay(point); // pases the ray and a new object with type RaycastHit if (Physics.Raycast(ray, out RaycastHit hit)) { // this retrieves the object the ray hit GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); GameObject enemy = hit.transform.gameObject; WanderingAI lifeStatus = enemy.GetComponent <WanderingAI>(); // this checks if the target is a person though the get component method and if it is // it returns a hit and if not it creates a sphere in the debug console. // get component returns null if the component isnt there. if ((target != null) && (lifeStatus.getAlive())) { target.ReactToHit(); Messenger.Broadcast(GameEvent.ENEMY_HIT); } else { // starts the coroutine kicking control to it StartCoroutine(SphereIndicator(hit.point)); } } } } }
void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); if (target != null) { if (hitObject.tag == "VulnerableToPistol" && !isRifleEquiped) { target.ReactToHit(); } else if (hitObject.tag == "VulnerableToRifle" && isRifleEquiped) { target.ReactToHit(); } } else { StartCoroutine(SphereIndicator(hit.point)); } } } if (Input.GetKeyDown(KeyCode.Q)) { isRifleEquiped = !isRifleEquiped; sniperRifle.SetActive(isRifleEquiped); pistol.SetActive(!isRifleEquiped); } if (Input.GetMouseButton(1) && isRifleEquiped) { _camera.fieldOfView = 30; } else { _camera.fieldOfView = 60; } }
void OnTriggerEnter(Collider other) { ReactiveTarget target = other.GetComponent <ReactiveTarget>(); if (target != null) { target.ReactToHit(); } Destroy(this.gameObject); }
void OnTriggerEnter(Collider other) { ReactiveTarget Enemy = other.GetComponent <ReactiveTarget>(); if (Enemy != null) { Enemy.ReactToHit(damage); } Destroy(this.gameObject); }
void Update() { if (_alive) { Ammo l = FindObjectOfType <Ammo> (); if (l != null) { lammo = l.getLammo(); } Ammo s = FindObjectOfType <Ammo> (); if (s != null) { sammo = s.getSammo(); } if ((Playerweapon.activeInHierarchy && Playerweapon.name.Contains("Handgun") && sammo > 0) || (Playerweapon.activeInHierarchy && Playerweapon.name.Contains("AK-47") && lammo > 0)) { if (Input.GetMouseButtonDown(0)) { if (Playerweapon.name.Contains("Handgun")) { handgun.Play(); } else if (Playerweapon.name.Contains("AK-47")) { ak47.Play(); } Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget> (); Boss b = hitObject.GetComponent <Boss> (); if (target != null) { target.ReactToHit(); } else if (b != null) { b.ReactToHit(); } else { StartCoroutine(BulletHole(hit.point, hit)); } } } } } }
void Update() { if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { source.Play(); Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; if (hitObject.GetComponent <Rigidbody> () != null) { (hitObject.GetComponent <Rigidbody> ()).AddForce(transform.forward * 5); } ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); if (target != null) { //print ("hit enemy"); target.ReactToHit(); } else { if (gun == 0) { StartCoroutine(SphereIndicator(hit.point)); } else { StartCoroutine(SphereIndicator2(hit.point)); } } } } if (Input.GetMouseButtonDown(1)) { if (gun == 0) { gun = 1; gunobject1.SetActive(false); gunobject2.SetActive(true); } else if (gun == 1) { gunobject1.SetActive(true); gunobject2.SetActive(false); gun = 0; } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) //if (Input.touchCount == 1) { // Touch touch = Input.GetTouch(0); // if (touch.phase == TouchPhase.Began) //{ Vector3 point = new Vector3(_cam.pixelWidth / 2, _cam.pixelHeight / 2, 0); Ray ray = _cam.ScreenPointToRay(point); RaycastHit hit; _bullet = Instantiate(bulletPrefab) as GameObject; _bullet.transform.position = transform.TransformPoint(Vector3.forward * 1.5f); _bullet.transform.forward = transform.forward; _bullet.transform.parent = transform.parent; if (Physics.Raycast(ray, out hit, Mathf.Infinity, lm)) { Debug.Log("Enemy hit: " + hit.collider.gameObject.name); GameObject hitObject = hit.transform.gameObject; ReactiveTarget target = hitObject.GetComponent <ReactiveTarget>(); //bulletFn.GetPoints(hit.point); if (target != null) { if (true) { target.ReactToHit(damage); } else if (hitObject.name == "8") { target.ReactToHit(critical); } } //StartCoroutine(HitIndicate(hit.point)); } } }