zoukankan      html  css  js  c++  java
  • 点击地面时,若鼠标点击的偶数次使得Cube向点击点移动,并且点击奇数次Cube变色

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class ray10 : MonoBehaviour
    {
        int num = 0;
        Vector3 vec;
        GameObject obj;
        bool b = false;
        Color[] a = { Color.blue, Color.cyan, Color.gray, Color.green, Color.red, Color.yellow };
    
        // Use this for initialization
        void Start()
        {
            //GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            //obj.transform.position = Vector3.zero;//one表示坐标(1,1,1)
            //obj.transform.localScale = new Vector3(1, 1, 1);//大小设置
        }
    
        // Update is called once per frame
        void Update()
        {
            
    
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    vec = hit.point;
                    num++;
    
                    if (num % 2 == 0)//偶数次
                    {
                        transform.LookAt(new Vector3(vec.x, vec.y + 0.5f, vec.z));
                        b = true;
                    }
                    if(num%2!=0)
                    {
                        GetComponent<MeshRenderer>().material.color = a[Random.Range(0, a.Length)];
                       
                    }
                }
    
            }
                if (b)
                {
                  transform.Translate(0, 0, 10 * Time.deltaTime);
                    if (Vector3.Distance(transform.position, new Vector3(vec.x, vec.y + 0.5f, vec.z)) < 0.1f)
                    {
                        b = false;
    
                    }
                }
        }
    }
    莫说我穷的叮当响,大袖揽清风。 莫讥我困时无处眠,天地做床被。 莫笑我渴时无美酒,江湖来做壶。
  • 相关阅读:
    【u026】花园(garden)
    【BZOJ 1040】[ZJOI2008]骑士
    【t100】汤姆斯的天堂梦
    【BZOJ 1038】[ZJOI2008]瞭望塔
    【t096】树的序号
    Java Web整合开发(82)
    2 HTML解析
    T3186 队列练习2 codevs
    T3185 队列练习1 codevs
    T1191 数轴染色 codevs
  • 原文地址:https://www.cnblogs.com/huang--wei/p/9609191.html
Copyright © 2011-2022 走看看