[Unity][Animator]抽奖卡牌

 

 

 

 

 


 

主摄像机的 Rotation的 X 为90,使其正对着Panel

[Unity][Animator]抽奖卡牌

 


using UnityEngine;
using UnityEngine.AI;

public class Test_Card : MonoBehaviour {

    public Camera cam;//主摄像机
    public int hitDistance = 1000;

    /// <summary>
    /// 抽奖卡牌 实体
    /// </summary>
    public Transform card1;
    /// <summary>
    /// 抽奖卡牌 实体
    /// </summary>
    public Transform card2;
    /// <summary>
    /// 抽奖卡牌 实体
    /// </summary>
    public Transform card3;

    /// <summary>
    /// 抽奖卡牌 实体,移动的目的地
    /// </summary>
    public Transform trans_Pos1;
    /// <summary>
    /// 抽奖卡牌 实体,移动的目的地
    /// </summary>
    public Transform trans_Pos2;
    /// <summary>
    /// 抽奖卡牌 实体,移动的目的地
    /// </summary>
    public Transform trans_Pos3;

    // Use this for initialization 当程序 运行时,一开始运行的代码
    void Start () {

        if (card1 != null && trans_Pos2 != null)
        {
            card1.GetComponent<NavMeshAgent>().SetDestination(trans_Pos2.position); ;//using UnityEngine.AI;
            card1.transform.GetComponent<Animator>().Play("TestCard_Card", 0);//播放动画
        }

        if (card2 != null && trans_Pos3 != null)
        {
            card2.GetComponent<NavMeshAgent>().SetDestination(trans_Pos3.position); ;//using UnityEngine.AI;
            card2.transform.GetComponent<Animator>().Play("TestCard_Card", 0);
        }

        if (card3 != null && trans_Pos1 != null)
        {
            card3.GetComponent<NavMeshAgent>().SetDestination(trans_Pos1.position); ;//using UnityEngine.AI;
            card3.transform.GetComponent<Animator>().Play("TestCard_Card", 0);
        }
    }
	
	// Update is called once per frame
	void Update () {

        Ray ray = cam.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        int layA = LayerMask.NameToLayer("Card");
        if (
               Physics.Raycast(
                   ray, out hit, 1000, (1 << layA)
                   )
               //&& hit.collider.gameObject.layer == LayerMask.NameToLayer("Floor")
               )//从 主摄像机发出射线
        {
            if (hit.collider.gameObject.layer == layA
                && Input.GetMouseButton(1))// 判断鼠标点击右键
            {
                Animator animator;
                //Debug.Log("    hit.point:" + hit.point);
                animator = hit.transform.GetComponent<Animator>();
                //animator.Play("TestCard_Card",0);//播放卡牌动画
                animator.SetBool("isTrans", true);
            }

            if (Input.GetMouseButton(0)
                && hit.collider.gameObject.layer == layA
                && hit.transform.GetComponent<Test_CardReward>() != null)// 判断鼠标点击左键
            {
                Animator animator;
                //Debug.Log("    hit.point:" + hit.point);
                animator = hit.transform.GetComponent<Animator>();
                //animator.Play("showReward", 0);//播放卡牌动画
                animator.SetBool("isClick", true);
                animator.SetBool("isTrans", false);
            }
        }
    }
}

 

 


 

[Unity][Animator]抽奖卡牌

 

 

 

 

参考资料:

1.unity去掉物体的阴影

2.

3.

相关文章: