在上一次我们的不懈努力几行代码下,方块君想要移动的愿望算是满足了,然而第二个愿望——射击,算是暂时把神大人难住了:
作为一个伪3D游戏,假透视是绝对有必要去做的,但是随着方块君的左右移动量不同,子弹射出的角度也不同
不过现在先把发射子弹的函数做出来再说,船到桥头自然直嘛!于是将这个shoot()函数放进方块君的操作脚本里
void shoot(GameObject bul)
{
Instantiate(bul, transform.position, Quaternion.identity);
}
蓝鹅……至少现在并没有什么用处……
让我们再度分析一下吧:
我们可以得出一个三角形的两边三角,于是乎,由于速度是矢量可以平移,我们可以用两个方向的Translate()来对子弹运动进行模拟:
此外,我们还需要判断子弹前进的大方向:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bullet : MonoBehaviour {
public float speedy, speedx, xsetoff, xangle;
public string dir;
void FixedUpdate () {
transform.Translate(Vector2.