2023.12.11号
0.游戏设计
脑海里设计完毕,为横板过关游戏,砍树,碎石,躲避蜜蜂投掷物袭击,击杀拦路敌人,解谜,探险。
1.资源导入
2.架设场景
3.今日份完成工作
1.编写寿命脚本
使一些物体拥有寿命,玩家的某些行为能与物体进行交互,进行一定改变。
暂时只设计了树木与石头的寿命
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class shoumingMannager : MonoBehaviour
{
public float shouming = 3;
public float shitou = 3;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
GetComponent<Animator>().SetFloat("shouming", shouming);
GetComponent<Animator>().SetFloat("shitouming", shitou);
}
public void jianshaoshouming()
{
shouming--;
}
public void suishi()
{
shitou--;
}
}
2.制作了树木“死亡”时动画与动画状态
实现与玩家的基本交互
3.制作NPC触发器与对话UI
使用invoke进行延时显示下一段话语,使对话小幅度浮升提升体验
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class duihua1 : MonoBehaviour
{
public GameObject canvas;
public TextMeshProUGUI TextMeshPro;
// Start is called before the first frame update
private void Start()
{
canvas.SetActive(false);
}
void Update()
{
if(canvas.active==true)
{
canvas.transform.Translate(0, 0.005f, 0);
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag=="Player222")
{
canvas.SetActive(true);
Invoke("lianzhao1", 2f);
}
}
public void lianzhao1()
{
TextMeshPro.GetTextInfo("你应该是从上面掉下来的吧,虽然不知道你发生了什么");
canvas.transform.position = new Vector3(-3.7f, 1.27f, 0);
Invoke("lianzhao2", 2f);
}
public void lianzhao2()
{
TextMeshPro.GetTextInfo("想出去的话出口就在前面,一直走就能看到一口井");
canvas.transform.position = new Vector3(-3.7f, 1.27f, 0);
Invoke("lianzhao3", 2f);
}
public void lianzhao3()
{
canvas.SetActive(false);
}
}
4.实现靠近树木触发按键提示
树木有碰撞体玩家需要“砍倒”后才能过去,提示小幅度上下浮动提升观感,寿命归零后消失
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class duihuatree : MonoBehaviour
{
public GameObject canvas;
public TextMeshProUGUI TextMeshPro;
bool shangxia;
// Start is called before the first frame update
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Player222")
{
canvas.SetActive(true);
}
}
private void Start()
{
canvas.SetActive(false);
}
private void Update()
{
if(canvas.active==true)
{
if(shangxia?true:false)
{
transform.Translate(new Vector3(0, 0.001f, 0));
Invoke("shang", 1f);
}
else
{
transform.Translate(new Vector3(0, -0.001f, 0));
Invoke("xia", 1f);
}
}
if(GetComponentInParent<shoumingMannager>().shouming==0)
{
Destroy(gameObject);
}
}
void shang()
{
shangxia = false;
}
void xia()
{
shangxia = true;
}
}
今日份工作到此,明天加油!!!