第六回 施法动作,法术路径及敌人选择

今天走堂,然后催促自己不能浪费走堂的时间,就学了很多。

首先呢,是加一个火球,让火球从法杖处飞至敌人处。


然后在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的设置



在敌人的设置中添加


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值