This script resets the ball to the proper position. It will put the ball infront of one of the players on the team who is going to get the ball. This could be due to a penalty or a goal.
Inheritance: MonoBehaviour
    //------------------------------------------------------------------------------------------------------

    void Awake()
    {
        trackedObj = GetComponent <SteamVR_TrackedObject>();

        laser     = GetComponentInChildren <LineRenderer>();
        ballReset = GameObject.FindObjectOfType <BallReset>();
    }
        private BallReset setup()
        {
            GameObject RedSideCenter = new GameObject("RSC");
            RedSideCenter.transform.position = new Vector3(1, 1, 1);
            GameObject RedSideLeft = new GameObject("RSL");
            RedSideLeft.transform.position = new Vector3(2, 2, 2);
            GameObject RedSideRight = new GameObject("RSR");
            RedSideRight.transform.position = new Vector3(3, 3, 3);
            GameObject BlueSideCenter = new GameObject("BSC");
            BlueSideCenter.transform.position = new Vector3(-1, -1, -1);
            GameObject BlueSideLeft = new GameObject("BSL");
            BlueSideLeft.transform.position = new Vector3(-2, -2, -2);
            GameObject BlueSideRight = new GameObject("BSR");
            BlueSideRight.transform.position = new Vector3(-3, -3, -3);

            GameObject Ball = new GameObject("Ball");
            Ball.AddComponent<Possession>();
            Ball.AddComponent<Rigidbody>();
            Ball.transform.position = Vector3.zero;

            BallReset BR = new BallReset();
            BR.Ball = Ball;
            BR.RedSideCenter = RedSideCenter;
            BR.RedSideLeft = RedSideLeft;
            BR.RedSideRight = RedSideRight;
            BR.BlueSideCenter = BlueSideCenter;
            BR.BlueSideLeft = BlueSideLeft;
            BR.BlueSideRight = BlueSideRight;
            return BR;
        }
Exemple #3
0
    /// <summary>
    /// Reset the ball position and current drawn line then change the level
    /// </summary>
    protected virtual void OnTrackingFound()
    {
        BallReset reset = GameObject.FindGameObjectWithTag("Player").GetComponent <BallReset>();

        lineReset.points.Clear();
        reset.ResetBall();
        levelChanger.ChangeLevel();
    }
 // Use this for initialization
 void Start()
 {
     sr   = GetComponent <SpriteRenderer> ();
     ball = GameObject.Find("Ball");
     br   = ball.GetComponent <BallReset> ();
     bc   = GetComponent <BoxCollider2D> ();
     pm   = GetComponentInParent <PlayerMovement> ();
 }
Exemple #5
0
    /// <summary>
    /// Initialize all variables needed for this script to run.
    /// </summary>
    void Start () 
    {
        timer = GetComponent<Timer>();
        timer.SetLengthOfTimer(halfLength + 1);
        timer.Pause();
        referee = GameObject.FindGameObjectWithTag("Referee").GetComponent<Referee>();
        GameObject gameController = GameObject.FindGameObjectWithTag("GameController");
        scoreKeeper = gameController.GetComponent<ScoreKeeper>();
        ballReset = gameController.GetComponent<BallReset>();
        breakTimer = GameObject.Find("BreakTimer").GetComponent<BreakTimer>();
	}
    public IEnumerator ResetBall(GameObject targetBall)
    {
        yield return(new WaitForSecondsRealtime(2f));

        //set camera position codes here
        BallReset resetScript = targetBall.GetComponent <BallReset>();

        resetScript.ResetBallPos();
        goalMessage.SetActive(false);
        Time.timeScale = 1f; //resume game upon resetting ball position
    }
Exemple #7
0
    void Start()
    {
        levelComplete       = false;
        rend                = GetComponent <Renderer>();
        rend.enabled        = true;
        rend.sharedMaterial = material[0];

        boxCollider  = GameObject.Find("GoalTrigger").GetComponent <BoxCollider>();
        collectibles = GameObject.Find("CollectibleController").GetComponent <CollectibleController>();
        ballReset    = GameObject.Find("Ball").GetComponent <BallReset>();
    }
    /// <summary>
    /// Gets the objects and initializes the variables to their proper values.
    /// </summary>
    void Start ()
    {
        if (isServer)
        {
            BlueTeamScore = 0;
            RedTeamScore = 0;
        }
        GameObject gameController = GameObject.FindGameObjectWithTag("GameController");

        GT = gameController.GetComponent<GameTimer>();
        BR = gameController.GetComponent<BallReset>();
        Ref = GameObject.FindGameObjectWithTag("Referee").GetComponent<Referee>();
        BT = GameObject.Find("BreakTimer").GetComponent<BreakTimer>();
	}
Exemple #9
0
    void GrabObject(Collider coli)
    {
        BallReset br = coli.GetComponent <BallReset>();

        if (br != null && br.isThrowed == true)
        {
            Debug.Log("Can't take it");
        }
        else
        {
            coli.transform.SetParent(gameObject.transform);
            coli.GetComponent <Rigidbody>().isKinematic = true;
            device.TriggerHapticPulse(2000);
        }
    }
Exemple #10
0
    /// <summary>
    /// Initializes all of the objects and variables needed for this script.
    /// </summary>
    void Start () 
    {
        GameObject GameController = GameObject.FindGameObjectWithTag("GameController");
        REF = GameObject.FindGameObjectWithTag("Referee").GetComponent<Referee>();
        BR = GameController.GetComponent<BallReset>();
        GT = GameController.GetComponent<GameTimer>();
        BT = GameObject.Find("BreakTimer").GetComponent<BreakTimer>();
        
        ballPossession = ball.GetComponent<Possession>();
        ballLocation = ball.GetComponent<ListObjectLocation>();
        timer = gameObject.AddComponent<Timer>();
        timer.SetLengthOfTimer(TimerFoulTime);
        timer.Resume();
        DeadBallTimer = gameObject.AddComponent<Timer>();
        DeadBallTimer.SetLengthOfTimer(DeadBallTime);
        DeadBallTimer.Pause();
	}
Exemple #11
0
    void ThrowObject(Collider coli)
    {
        coli.transform.SetParent(null);
        Rigidbody rigidBody = coli.GetComponent <Rigidbody>();

        if (!coli.gameObject.CompareTag("Structure"))
        {
            rigidBody.isKinematic     = false;
            rigidBody.velocity        = device.velocity * throwForce;
            rigidBody.angularVelocity = device.angularVelocity;
            BallReset br = coli.GetComponent <BallReset>();
            if (br != null)
            {
                br.isThrowed = true;
            }
        }
    }
    private void ThrowObject(Collider col)
    {
        col.transform.SetParent(null);
        Rigidbody rigidBody = col.GetComponent <Rigidbody>();

        // Debug.Log("Throwing " + col.gameObject.name);
        if (rigidBody == null)
        {
            return;
        }
        if (col.gameObject.CompareTag("Throwable"))
        {
            rigidBody.isKinematic = false;
            // col.gameObject.GetComponent<Collider>().isTrigger = true;
            rigidBody.velocity        = OVRInput.GetLocalControllerVelocity(thisController) * throwForce;
            rigidBody.angularVelocity = OVRInput.GetLocalControllerAngularVelocity(thisController);

            //set the corresponding material depending on where the player threw
            //
            if (isGrabbingObject)
            {
                BallReset ballScript           = col.gameObject.GetComponent <BallReset>();
                bool      IsStandingOnPlatform = platformCheck.IsOnPlatform();
                if (IsStandingOnPlatform)
                {
                    ballScript.ApplyGreenGlow();
                }
                else
                {
                    ballScript.ApplyRedGlow();
                }
            }
        }
        isGrabbingObject = false;

        // Debug.Log("Released Object");
    }
Exemple #13
0
    /// <summary>
    /// Initializes all variables needed to run the script.
    /// </summary>
    void Start ()
    {
        GameObject GameController = GameObject.FindGameObjectWithTag("GameController");
        BR = GameController.GetComponent<BallReset>();
        GT = GameController.GetComponent<GameTimer>();
        
        CF = new CoinFlip();
        if (CF.Flip())
        {
            // Red team won toss, blue will get ball next half
            ball.GetComponent<Possession>().SetNextHalfPossession(Possession.Team.blue);
            // Give the ball to the red team
            BR.placeBallRSC();
        }
        else
        {
            // Blue team won toss, red will get the ball next half
            ball.GetComponent<Possession>().SetNextHalfPossession(Possession.Team.red);
            // Give the ball to the blue team
            BR.placeBallBSC();
        }

        setupDone = true;
    }