Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考
此代码仅为较上一P有所改变的代码
【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili
Clone_Skill.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Clone_Skill : Skill
{
[Header("Clone")]
[SerializeField] private GameObject clonePrefah;//克隆原型
[SerializeField] private float cloneDuration;//克隆持续时间
public void CreateClone(Transform _clonePosition)//传入克隆位置
{
GameObject newClone = Instantiate(clonePrefah);//创建新的克隆//克隆 original 对象并返回克隆对象。
//https://docs.unity3d.com/cn/current/ScriptReference/Object.Instantiate.html
newClone.GetComponent<Clone_Skill_Controller>().SetupClone(_clonePosition,cloneDuration);//调试clone的位置,同时调试克隆持续时间
//Controller绑在克隆原型上的,所以用GetComponents,
}
}
Clone_Skill_Controller.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//Clone_Skill_Controller是绑在Clone体上的也就是Prefah上的
public class Clone_Skill_Controller : MonoBehaviour
{
private SpriteRenderer sr;//定义Sr
[SerializeFie