예제 #1
0
파일: Ball.cs 프로젝트: rx-pku/Unity
    public void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.transform.tag == "Left" || collision.transform.tag == "Right")
        {
            MoveRacket other = collision.gameObject.GetComponent <MoveRacket>();
            if (other.IsBlue != IsBlue)
            {
                timer = 5;
                isrun = false;
                // GetComponent<Rigidbody2D>().transform.position = new Vector2(0, 0);
                GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0);
                if (collision.transform.tag == "Left")
                {
                    score_right++;
                }
                else
                {
                    score_left++;
                }
                InvokeRepeating("countdown", 1, 1);
            }
        }
        else if (collision.transform.tag == "door_left" || collision.transform.tag == "door_right")
        {
            timer = 5;
            isrun = false;
            // GetComponent<Rigidbody2D>().transform.position = new Vector2(0, 0);

            GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0);
            if (collision.transform.tag == "door_left")
            {
                score_right++;
            }
            else
            {
                score_left++;
            }
            InvokeRepeating("countdown", 1, 1);
        }
    }
예제 #2
0
 // Use this for initialization
 void Start()
 {
     GetComponent <Rigidbody2D>().velocity = new Vector2(1, 0) * speed;
     LRacket = LR.GetComponent <MoveRacket>();
     RRacket = RR.GetComponent <MoveRacket>();
 }
예제 #3
0
파일: Ball.cs 프로젝트: johnt447/Pongo
    // Update is called once per frame
    void Update()
    {
        SlideL.value =PowerL;
        SlideR.value =PowerR;

        if (ScoreL >= 10 || ScoreR >= 10)
        {
            if (CHECK==false)
            {
                CHECK=true;
                StartTime = Time.time;
            }

                if (ScoreL >= 10)
                {
                GameOverText.GetComponent<Text> ().text ="Game   Over\nPlayer 1 wins";
                }

                if (ScoreR >= 10)
                {
                GameOverText.GetComponent<Text> ().text ="Game   Over\nPlayer 2 wins";
                }

            if (Time.time > StartTime+delay)
            {
                Application.LoadLevel ("StartScreen");
            }
        }

        if (Input.GetKeyDown ("space") && BallInPlay == false && this.gameObject.name!="Ball(Clone)") {
            if (Server=="L"){GetComponent<Rigidbody2D>().velocity = Vector2.right * speed; }
                if (Server=="R"){GetComponent<Rigidbody2D>().velocity = Vector2.left * speed; }
            GetComponent<TrailRenderer>().enabled = true;
            BallInPlay=true;
        }

        if (Input.GetKey ("a")) {
            PowerL += Time.deltaTime;
            if (PowerL>= MaxPower){ PowerL=MaxPower; }

            racketLeft.speed=PowerUpspeedL;
        }

        if (Input.GetKeyUp ("a")) {
            PowerL = 1;
            racketLeft.speed=speed;
        }

        if (AI == false) {
            if (Input.GetKey ("right")) {
                PowerR += Time.deltaTime;
                if (PowerR >= MaxPower) {
                    PowerR = MaxPower;
                }

                racketRight.speed = PowerUpspeedR;
            }

            if (Input.GetKeyUp ("right")) {
                PowerR = 1;
                racketRight.speed = speed;
            }
        }

        if (AI == true) {

            AI racketRight;
            RackRight = GameObject.Find("RacketRight");
            racketRight = RackRight.GetComponent<AI>();

            float distance = Mathf.Abs(RightRacket.transform.position.y-  racketRight.ProjectedPos) ;
            //Debug.Log(racketRight.ProjectedPos);
            //Lets do the AI power stuff
            if (distance < PowerUpAIDist)
            {
                PowerR += Time.deltaTime;
                if (PowerR >= MaxPower) {
                    PowerR = MaxPower;
                }

                racketRight.speed = PowerUpspeedR;
            }

            if (distance > PowerUpAIDist)
            {
                PowerR = 1;
                racketRight.speed = speed;
            }

        }
    }
예제 #4
0
파일: Ball.cs 프로젝트: johnt447/Pongo
    // Use this for initialization
    void Start()
    {
        StartGame.Play ();
        StartingPosL = transform.position;
        StartingPosR = transform.position + new Vector3(240,0,0);

        RackLeft = GameObject.Find("RacketLeft");
        racketLeft = RackLeft.GetComponent<MoveRacket>();

        RackRight = GameObject.Find("RacketRight");
        racketRight = RackRight.GetComponent<MoveRacket>();
    }
예제 #5
0
 private void Start()
 {
     moveRacket = gameObject.GetComponent <MoveRacket>();
     bot        = gameObject.GetComponent <Bot>();
 }