欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當前位置:主頁 > 軟件編程 > C#教程 >

Unity3D實現(xiàn)旋鈕控制燈光效果

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點擊: 次

本文實例為大家分享了Unity3D實現(xiàn)旋鈕控制燈光效果的具體代碼,供大家參考,具體內(nèi)容如下

前言

       實際上使用的是非常簡單的方式,通過開啟以及關(guān)閉帶有燈光效果物體的渲染以模擬出的燈光切換效果。

       正確方式應(yīng)當為物體切換不同的Material實現(xiàn)效果。

所用函數(shù)

public void RotateAround(Vector3 point, Vector3 axis, float angle);
    //通過給定一個世界坐標、軸向以及一個角度,使物體以該角度旋轉(zhuǎn)繞世界坐標點的軸向的變換
  
  public T GetComponent<T>();
    //獲取對象的組件
 
  public bool enabled { get; set; }
    //設(shè)置激活狀態(tài) 

實現(xiàn)代碼

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class RotateControl : MonoBehaviour {
 
  public GameObject RedLight;//紅燈
  public GameObject GreenLight;//綠燈
  public GameObject Center;//旋轉(zhuǎn)中心,若為自身則指定自身
 
  private bool isOn = false;//正在開啟
  private bool isOff = false;//正在關(guān)閉
  [Range(0,180)]
  public float onLine = 80;//旋鈕最大角度
  [Range(0,180)]
  private float offLine = 0;//旋鈕最小角度
  [Range(0,3)]
  public float speed = 1;//旋轉(zhuǎn)速度
  [Range(0, 20)]
  public float LightingRange = 10;//亮燈角度與旋鈕最大角度的角度差
 
  // Use this for initialization
  void Start () {
    isOn = false;
    isOff = false;
    offLine = Center.transform.rotation.z;//設(shè)定起始位置即為最小角度
    RedLight.GetComponent<Renderer>().enabled = false;//關(guān)閉紅燈渲染
    GreenLight.GetComponent<Renderer>().enabled = false;//關(guān)閉綠燈渲染
  }
 
 // Update is called once per frame
 void Update () {
    if (Input.GetKeyDown(KeyCode.R))//關(guān)閉
    {
      isOn = false;
      isOff = true;
    }
    if (Input.GetKeyDown(KeyCode.G))//開啟
    {
      isOn = true;
      isOff = false;
    }
 
    if (isOn == true)
    {
      if (this.transform.eulerAngles.z < onLine)//旋鈕旋轉(zhuǎn)至最大角度
      {
        this.transform.RotateAround(this.transform.position, this.transform.forward, speed);
      }
      else
      {
        isOn = false;
      }
    }
    if (isOff == true)
    {
      if (this.transform.eulerAngles.z > offLine + 1)//旋轉(zhuǎn)至最小角度+1°的角度,當物體旋轉(zhuǎn)到0時繼續(xù)旋轉(zhuǎn)則變?yōu)?60度
      {
        this.transform.RotateAround(this.transform.position, this.transform.forward, -speed);
      }
      else
      {
        isOff = false;
      }
    }
 
    //檢測旋轉(zhuǎn)角度控制燈光
    if (this.transform.eulerAngles.z >= onLine - LightingRange)//當旋鈕旋轉(zhuǎn)角度大于閾值則渲染綠燈,關(guān)閉紅燈
    {
      RedLight.GetComponent<Renderer>().enabled = false;
      GreenLight.GetComponent<Renderer>().enabled = true;
    }
    else
    {
      RedLight.GetComponent<Renderer>().enabled = true;
      GreenLight.GetComponent<Renderer>().enabled = false;
    }
  }
}

關(guān)于物體的旋轉(zhuǎn)

       由于很少情況會在物體剛好旋轉(zhuǎn)到我們所期望的角度時進行一次判定,所以物體旋轉(zhuǎn)角度一般會超過你所期望的角度。

       當物體由一個正向的角度向0°方向旋轉(zhuǎn)時,物體角度低于0°時物體角度會變?yōu)?60°

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持我們。

上一篇:C#獲取App.Config配置項的方法總結(jié)

欄    目:C#教程

下一篇:C#使用HttpWebRequest重定向方法詳解

本文標題:Unity3D實現(xiàn)旋鈕控制燈光效果

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/4795.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有