『unity 背景を動かす』

unity2020.1.14f

背景を動かす事によりプレイヤーが移動しているように感じさせるために使用しています。

<スクリプト>

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

public class start : MonoBehaviour
{
public float speed = 1.0f;
private Text text;
private Image image;
private float time;
private enum ObjType
{
TEXT,
IMAGE
};
private ObjType thisObjType = ObjType.TEXT;
void Start()
{
If (this.gameObject.GetComponent())
{
thisObjType = ObjType.IMAGE;
image = this.gameObject.GetComponent();
}
else if (this.gameObject.GetComponent())
{
thisObjType = ObjType.TEXT;
text = this.gameObject.GetComponent();
}
}
void Update()
{
if (thisObjType == ObjType.IMAGE)
{
image.color = GetAlphaColor(image.color);
}
else if (thisObjType == ObjType.TEXT)
{
text.color = GetAlphaColor(text.color);
}
}
Color GetAlphaColor(Color color)
{
time += Time.deltaTime * 5.0f * speed;
color.a = Mathf.Sin(time) * 0.5f + 0.5f;
return color;
}
}

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

コメント

コメントする

CAPTCHA


目次
閉じる