Exemple #1
0
    private void HarvestHay(Haystack haystack)
    {
        GetComponent <Rigidbody>().velocity        = Vector3.zero;
        GetComponent <Rigidbody>().angularVelocity = Vector3.zero;

        if (state != TractorState.HasHayAndPlayer)
        {
            if (timeHarvestHay >= haystack.timeHarvestRequired)
            {
                state = TractorState.HasHayAndPlayer;
                gameObject.GetComponent <PUN2_TractorSync>().callChangeState(3);
                timeHarvestHay = 0f;
                haystack.DecreaseHay();
                gameObject.GetComponent <PUN2_TractorSync>().callChangeStats(timeMove, false, timeHarvestHay);
                gameObject.GetComponent <PUN2_TractorSync>().callStopHarvestHaySound();
            }
            else
            {
                if (timeHarvestHay == 0)
                {
                    gameObject.GetComponent <PUN2_TractorSync>().callPlayHarvestHaySoundContinuous();
                }
                timeHarvestHay += Time.fixedDeltaTime;
                gameObject.GetComponent <PUN2_TractorSync>().callChangeStats(timeMove, true, timeHarvestHay);
                timeHarvestRequired = haystack.timeHarvestRequired;
            }
        }
    }
Exemple #2
0
    private void HandlePlayerExitTractor()
    {
        Vector3 tractorScale = transform.localScale;
        Vector3 playerScale  = playerPrefab.transform.localScale;
        Vector3 offsetScale  = Vector3.zero;        // offset due to scale

        // additional offset in the each direction when spawning player due to tractor and player's scale
        offsetScale.x += tractorScale.x % 2 == 0 ? 0f : 0.5f;
        offsetScale.z += tractorScale.z % 2 == 0 ? 0f : 0.5f;
        offsetScale.x += playerScale.x % 2 == 0 ? 0f : -0.5f;
        offsetScale.z += playerScale.z % 2 == 0 ? 0f : -0.5f;

        playerPos = new Vector3(0,
                                transform.position.y - tractorScale.y / 2f + playerScale.y / 2f + epsilon.y,
                                0);
        Vector3 offsetBoundary = Vector3.zero;         // offset to avoid spawning a player that collides with this tractor

        spawnedPlayer = false;
        //for (float x = -1; x < tractorScale.x + 1 && !spawnedPlayer; x++)
        //{
        //	offsetBoundary.x = 0f;
        //	if (x == -1) offsetBoundary.x = -epsilon.x;
        //	else if (x == tractorScale.x) offsetBoundary.x = epsilon.x;

        //	//for (float z = -1; z < tractorScale.z + 1 && !spawnedPlayer; z++)
        //	//{
        //		offsetBoundary.z = 0f;
        //		if (z == -1) offsetBoundary.z = -epsilon.z;
        //		else if (z == tractorScale.z) offsetBoundary.z = epsilon.z;

        //		playerPos.x = transform.position.x + 2f;//+ offsetScale.x + offsetBoundary.x + x;
        //												//playerPos.z = transform.position.z + offsetScale.z + offsetBoundary.z + z;

        //		//if (!PlayerOverlapOthers(playerPos, transform.rotation))
        //		//{
        //		//Instantiate(playerPrefab, playerPos, transform.rotation);

        //	//}
        //}

        spawnedPlayer        = true;
        timeSincePlayerEnter = 0f;
        if (state == TractorState.HasHayAndPlayer)
        {
            state = TractorState.HasHayOnly;
            gameObject.GetComponent <PUN2_TractorSync>().callChangeState(1);
        }
        else
        {
            state = TractorState.Empty;
            gameObject.GetComponent <PUN2_TractorSync>().callChangeState(0);
        }

        if (!spawnedPlayer)
        {
            Debug.Log("There's not enough space for player to get out off the tractor");
        }
    }
Exemple #3
0
 public bool GetHay()
 {
     if (state == TractorState.HasHayOnly)
     {
         state = TractorState.Empty;
         gameObject.GetComponent <PUN2_TractorSync>().callChangeState(0);
         return(true);
     }
     return(false);
 }
Exemple #4
0
 public void PlayerEnter()
 {
     if (state == TractorState.Empty)
     {
         state = TractorState.HasPlayerOnly;
         gameObject.GetComponent <PUN2_TractorSync>().callChangeState(2);
     }
     else if (state == TractorState.HasHayOnly)
     {
         state = TractorState.HasHayAndPlayer;
         gameObject.GetComponent <PUN2_TractorSync>().callChangeState(3);
     }
 }