技能指定点释放

public class Test : MonoBehaviour
{
 
    public GameObject particle;//粒子特效预设
    private RaycastHit hit;
    private Ray ray;
    private GameObject capsule;//角色
    private bool keydown;//判断是否按下对应技能键
    private GameObject par;//要创建的例子(要释放的技能)
    public GameObject firesprite;//2D Sprite的预设
    private GameObject fire;//要创建的Sprite
 
    // Use this for initialization
    void Start()
    {
        capsule = GameObject.Find("Capsule");
 
    }
 
 
    void Update()
    {
        // Vector3 gameposscreen = Camera.main.WorldToScreenPoint(capsule.transform.position);
        // Vector3 mouseposworld = Camera.main.ScreenToWorldPoint(new Vector3( Input.mousePosition.x,Input.mousePosition.y,gameposscreen.z));
        // capsule.transform.position = new Vector3(mouseposworld.x, 1,mouseposworld.z);//这几句就是把鼠标的屏幕坐标转为世界坐标的...主要是鼠标的<br>世界坐标跟物体在同一个xoz平面上,也就是y一样。
        if (Input.GetKeyDown(KeyCode.A))
        {
            keydown = true;
 
            fire = GameObject.Instantiate(firesprite, Vector3.zero, Quaternion.identity);//在这里创建Sprite
            fire.transform.Rotate(new Vector3(90, 0, 0));//旋转成水平方向
 
        }
        if (keydown)
        {
            if (Input.GetMouseButton(0))
            {
                ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit))//射线检测
                {
                    if (hit.collider != null)
                    {
                        var coll = new Vector3(hit.point.x, hit.point.y, hit.point.z);//射线检测的位置
                        fire.transform.position = new Vector3(coll.x, 1, coll.z);//付给Sprite
                    }
                }
            }
            if (Input.GetMouseButtonUp(0))
            {
                par = GameObject.Instantiate(particle, fire.transform.position, Quaternion.identity);//创建粒子特效(释放技能
          Destroy(fire);
          Destroy(par,5f);//摧毁

1
2
3
4
5
6
            }
        }
    }
 
 
}

  

posted @ 2020-03-27 16:35  青天明月夜  阅读(51)  评论(0)    收藏  举报