第一个工程3-代码解释二

来源:互联网 发布:qq飞车淘宝网 编辑:程序博客网 时间:2024/04/30 00:55

绑定在球杆上对球杆的控制,之所以还有个绑在空物体上的球杆控制,是由于一个物体不能SetActive(true)本身

StickSelfHitRelated.cs

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class StickSelfHitRelated : MonoBehaviour {
    public GameObject tableStickController;
    public GameObject whiteBallParticleSystem;
    private StickController stickController;

    private Vector3 startDirection; //水平方向


    public GameObject hitPowerGameObject;
    private Slider hitPower;
    //system configure
//    private float whiteBallStartSpeed = 10.0f;
    // Use this for initialization
    void Start () {
        
        stickController = tableStickController.GetComponent<StickController> ();
        hitPower = hitPowerGameObject.GetComponent<Slider> ();
    }
    
    // Update is called once per frame
    void Update () {
    
    }
    //这个碰撞是指杆和白球碰撞
    void OnTriggerEnter(Collider other)  {
        if (other.gameObject.CompareTag ("WhiteBall")) { //当杆的碰撞对象为
            startDirection = stickController.hitVector; //从stickController取得击球方向,这个向量y方向应该为0
            gameObject.transform.parent.gameObject.SetActive (false); //球杆消失,由于方向问题,碰撞体在子物体上,把父物体Active设为false,子物体跟着消失。
            whiteBallParticleSystem.SetActive (false); //白球上的击球线消失
            other.gameObject.GetComponent<Rigidbody> ().velocity = startDirection * hitPower.value/5.0f; //根据滚动条的值赋给白球速度,这样简单点

            SceneManager.isBallMoving = true; //设为true,表示一杆的开始,设为false,一杆结束是判断所有还存在的球静止时
            SceneManager.changePlayer = false; //在一杆把是否变换Player的标志位设为false,方便后面的处理,只有发生交换击球的情况才再改变changePlayer 
        }
    }
}

0 0
原创粉丝点击