2020.2版本以后移除了2D Sprite
添加2D Sprite
1.unity血条跟随。。。。。。。。。。。。。。。-C#文档类资源-CSDN下载
2.找到Square复制到UISprite文件下
制作血条
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BloodStrip : MonoBehaviour
{
// Start is called before the first frame update
public GameObject bloodStripPrefabs;
public Transform barPoint;
Image bloodStriteSlider;
Transform UIbar;
Transform cam;
public bool alwaysVisible;
void Start()
{
}
private void OnEnable()
{
cam = Camera.main.transform;
foreach (Canvas canvas in FindObjectsOfType
{
if (canvas .renderMode ==RenderMode.WorldSpace )
{
UIbar = Instantiate(bloodStripPrefabs, canvas.transform).transform;
// bloodStriteSlider = UIbar.GetChild(0).GetComponent
UIbar.gameObject.SetActive(alwaysVisible);
}
}
}
private void LateUpdate()
{
if (UIbar !=null)
{
UIbar.position = barPoint.position;
UIbar.forward = -cam.forward;
}
}
}
6.将制作好的Background预设体