今天走堂,然后催促自己不能浪费走堂的时间,就学了很多。
首先呢,是加一个火球,让火球从法杖处飞至敌人处。
然后在C#里面,开一个档案叫spell,在里面设置火球的路径
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class spell : MonoBehaviour {
private Rigidbody2D myRigidBody;
[SerializeField]
private float speed;
private Transform target;
// Use this for initialization
void Start () {
myRigidBody = GetComponent<Rigidbody2D>();
//just for testing and debuging
target = GameObject.Find("Target").transform;
}
// Update is called once per frame
void Update () {
}
private void FixedUpdate()
{
Vector2 direction = target.position - transform.position;
myRigidBody.velocity = direction.normalized * speed;
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}
}
然后呢,就要让无论从哪个方向都让火球位于法杖中心飞出。
切换上下左右四个面,把坐标调整至法杖中心。
然后建一个Block,作为挡住玩家施法的屏障。确保玩家只有在视线角度才能命中敌方
注意:隐藏时先√掉sprite renderer,再√object
通过这个debug找到layer的层数
敌人object的属性
block的设置
在敌人的设置中添加