8ydilnik

Raycast!

Oct 5th, 2019
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class sas : MonoBehaviour
  7. {
  8.     // Start is called before the first frame update
  9.  
  10.     public Material m1;
  11.  
  12.     public int score_eag;
  13.     public int score_psheno;
  14.     public int score_milk;
  15.     public int ALL_MONEY;
  16.  
  17.     public GameObject chiken;
  18.     public GameObject cow;
  19.     public GameObject field;
  20.  
  21.     public Text scoretext1;
  22.     public Text scoretext2;
  23.     public Text scoretext3;
  24.     void Start()
  25.     {
  26.  
  27.     }
  28.  
  29.     // Update is called once per frame
  30.     void FixedUpdate()
  31.     {
  32.  
  33.         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  34.         RaycastHit hit;
  35.         if (Physics.Raycast(ray, out hit) && Input.GetMouseButtonDown(0))
  36.         {
  37.             if (hit.collider.tag == "chiken")
  38.  
  39.             {
  40.                 score_eag += 1;
  41.                 ALL_MONEY += 15;
  42.                 chiken.gameObject.GetComponent<Renderer>().material = m1;
  43.                 scoretext1.text = "eag:" + score_eag;
  44.  
  45.             }
  46.  
  47.  
  48.             if (Physics.Raycast(ray, out hit) && Input.GetMouseButtonDown(0))
  49.            
  50.                 if (hit.collider.tag == "cow")
  51.  
  52.                 {
  53.                 score_psheno += 1;
  54.                     ALL_MONEY += 40;
  55.                     chiken.gameObject.GetComponent<Renderer>().material = m1;
  56.                     scoretext2.text = "milk:" + score_milk;
  57.                 }
  58.  
  59.  
  60.                 if (Physics.Raycast(ray, out hit) && Input.GetMouseButtonDown(0))
  61.                
  62.                     if (hit.collider.tag == "field")
  63.  
  64.                   {
  65.                      score_milk += 1;
  66.                     ALL_MONEY += 20;
  67.                     scoretext3.text = "field:" + score_psheno;
  68.                     chiken.gameObject.GetComponent<Renderer>().material = m1;
  69.             }
  70.  
  71.                
  72.         }
  73.     }
Advertisement
Add Comment
Please, Sign In to add comment