如何在Unity3D中访问渐变编辑器?

时间:2015-01-27 01:33:27

标签: colors background unity3d

我正在搜索Unity手册,看看它们对渐变效果有什么影响,我发现了这个:

enter image description here

这是链接:

http://docs.unity3d.com/Manual/EditingValueProperties.html

但是,我无法在Unity内部的任何地方找到此编辑器。我想用这个来为我的游戏背景应用渐变。它存在吗??

2 个答案:

答案 0 :(得分:2)

您无权使用颜色选择器或渐变编辑器。为了制作背景,你有几个选择,

  1. 从编辑器中更改Camera background color
  2. 使用Skybox,您也可以make your own skybox
  3. 如果您的游戏视野有限,请使用带custom material的飞机。

答案 1 :(得分:1)

也许这个脚本显示了如何使用Gradients。您需要将此脚本添加到场景中的GameObject之一。您的Camera标记为MainCamera

此代码基于this

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class GradientHandler : MonoBehaviour {

    public Camera camera;
    public Gradient gradient;
    // Use this for initialization
    void Start () {
        camera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>() as Camera; //Gets Camera script from MainCamera object(Object's tag is MainCamera).
        GradientColorKey[] colorKey = new GradientColorKey[2];
        GradientAlphaKey[] alphaKey = new GradientAlphaKey[2];
        // Populate the color keys at the relative time 0 and 1 (0 and 100%)
        colorKey[0].color = Color.red;
        colorKey[0].time = 0.0f;
        colorKey[1].color = Color.blue;
        colorKey[1].time = 1.0f;
        // Populate the alpha  keys at relative time 0 and 1  (0 and 100%)
        alphaKey[0].alpha = 1.0f;
        alphaKey[0].time = 0.0f;
        alphaKey[1].alpha = 0.0f;
        alphaKey[1].time = 1.0f;
        gradient.SetKeys(colorKey, alphaKey);
    }

    // Update is called once per frame
    void Update () {
        Debug.Log ("Time: "+Time.deltaTime);
        camera.backgroundColor = gradient.Evaluate(Time.time%1);
    }
}