// Use this for initialization void Start() { //tomatoeBarrel = PlantsController.PlantType.Tomatoe; //potatoeBarrel = PlantsController.PlantType.Potatoe; //potatoe barrel GameObject carrotBarrelSpot = GameObject.FindGameObjectWithTag("CarrotBarrell"); GameObject newSeedBarrel = Instantiate(barrel, carrotBarrelSpot.transform.position, Quaternion.identity); BarellController newSeeds = newSeedBarrel.GetComponent <BarellController>(); newSeeds.YouAreA(BarellController.PlantType.Carrot); //tomatoe barrell GameObject tomatoeBarrelSpot = GameObject.FindGameObjectWithTag("TomatoeBarrell"); GameObject newSeedBarrel2 = Instantiate(barrel, tomatoeBarrelSpot.transform.position, Quaternion.identity); BarellController newSeeds2 = newSeedBarrel2.GetComponent <BarellController>(); newSeeds2.YouAreA(BarellController.PlantType.Tomatoe); //trash can GameObject newtrashBarrel = Instantiate(trashBarrel, new Vector3(1.02f, -0.3f, 5.92f), Quaternion.identity); //plucker GameObject shovelBarrelSpot = GameObject.FindGameObjectWithTag("ShovelBarrell"); GameObject newPluckerBarrel = Instantiate(pluckerBarrel, shovelBarrelSpot.transform.position, Quaternion.identity); //table GameObject table1 = GameObject.FindGameObjectWithTag("Table1"); GameObject table2 = GameObject.FindGameObjectWithTag("Table2"); GameObject table3 = GameObject.FindGameObjectWithTag("Table3"); GameObject table4 = GameObject.FindGameObjectWithTag("Table4"); GameObject newTable = Instantiate(table, table1.transform.position, Quaternion.identity); GameObject newTable2 = Instantiate(table, table2.transform.position, Quaternion.identity); GameObject newTable3 = Instantiate(table, table3.transform.position, Quaternion.identity); GameObject newTable4 = Instantiate(table, table4.transform.position, Quaternion.identity); }
private InHand Interact() { Ray lookAt = new Ray(transform.position, transform.forward); Debug.DrawRay(lookAt.origin, 15 * lookAt.direction, Color.red, 5); RaycastHit info; //the Array only works if it is in the range of 'raycastRange' if (Physics.Raycast(lookAt, out info, raycastRange)) { BarellController barrell = info.collider.GetComponent <BarellController>(); if (barrell)//if it has the script 'PlantsController' do this { if (currently_Holding == InHand.Empty) { BarellController.PlantType pickingUP = barrell.pickUp(); switch (pickingUP) { case BarellController.PlantType.Carrot: return(InHand.Carrot_Seeds); case BarellController.PlantType.Tomatoe: return(InHand.Tomatoe_Seeds); } } } plotControl plot = info.collider.GetComponent <plotControl>(); if (plot) { //Seed planting if (currently_Holding == InHand.Carrot_Seeds || currently_Holding == InHand.Tomatoe_Seeds) { if (plot.plotIs == plotControl.PlotState.Soil) { plot.InteractP2(currently_Holding); return(InHand.Empty); } } //plucker for removing the rubbish (grass) if (currently_Holding == InHand.Plucker) { if (plot.plotIs == plotControl.PlotState.Rubbish) { plot.InteractP2(currently_Holding); return(InHand.Plucker); } } //Once the plant is grown (tomato) if (currently_Holding == InHand.Empty) { if (plot.plotIs == plotControl.PlotState.Tomatoe_Plant) { plot.InteractP2(currently_Holding); return(InHand.Tomatoes); } } //Once the plant is grown (carrots) (so that the player could pick up the item) if (currently_Holding == InHand.Empty) { if (plot.plotIs == plotControl.PlotState.Carrot_Plant) { plot.InteractP2(currently_Holding); return(InHand.Carrots); } } } TrashController trash = info.collider.GetComponent <TrashController>(); if (trash) { return(InHand.Empty); } PluckerControl plucker = info.collider.GetComponent <PluckerControl>(); if (plucker) { if (currently_Holding == InHand.Empty) { return(InHand.Plucker); } } TableController table = info.collider.GetComponent <TableController>(); if (table) { if (currently_Holding == InHand.Empty) { if (table.SomethingOnTable()) { GameObject item = table.removeTopItem(); //add the script to the tomato and carrots prefab and add it to the table, + delete an extra table VegControl newplant = item.GetComponent <VegControl>(); if (newplant) { switch (newplant.thisIsA) { case VegControl.VegType.Carrot: return(InHand.Carrots); case VegControl.VegType.Tomatoe: return(InHand.Tomatoes); } } } } else { if (currently_Holding == InHand.Carrots) { table.putCarrotOn(); return(InHand.Empty); } if (currently_Holding == InHand.Tomatoes) { table.putTomatoOn(); return(InHand.Empty); } } } P2WagonController wagon = info.collider.GetComponent <P2WagonController>(); if (wagon) { if (currently_Holding == InHand.Carrots) { wagon.putCarrotOn(); return(InHand.Empty); } if (currently_Holding == InHand.Tomatoes) { wagon.putTomatoOn(); return(InHand.Empty); } } PlayerController playerHit = info.collider.GetComponent <PlayerController>(); if (playerHit) { GameObject player1; if (currently_Holding == InHand.Plucker) { if (player1 = GameObject.FindWithTag("Player1")) { player1.transform.position = new Vector3(playerHit.transform.position.x, transform.position.y + 7, transform.position.z); } } } } return(currently_Holding); }