Advertisement
evelynshilosky

Soil - Part 39

Apr 18th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class Soil : MonoBehaviour
  7. {
  8.     public bool isEmpty = true;
  9.  
  10.     public bool playerInRange;
  11.     public string plantName;
  12.  
  13.     public Plant currentPlant;
  14.  
  15.     public Material defaultMaterial;
  16.     public Material wateredMaterial;
  17.  
  18.     private void Update()
  19.     {
  20.         float distance = Vector3.Distance(PlayerState.Instance.playerBody.transform.position, transform.position);
  21.  
  22.         if (distance < 10f)
  23.         {
  24.             playerInRange = true;
  25.         }
  26.         else
  27.         {
  28.             playerInRange = false;
  29.         }
  30.     }
  31.    
  32.     internal void PlantSeed()
  33.     {
  34.         InventoryItem selectedSeed = EquipSystem.Instance.selectedItem.GetComponent<InventoryItem>();
  35.         isEmpty = false;
  36.  
  37.         string onlyPlantName = selectedSeed.thisName.Split(new string[] { " Seed" }, StringSplitOptions.None)[0];
  38.         plantName = onlyPlantName;
  39.  
  40.         // Instantiate Plant Prefab
  41.         GameObject instantiatedPlant = Instantiate(Resources.Load($"{onlyPlantName}Plant") as GameObject);
  42.  
  43.         // Set the instatiated plant to be a child of the Soil
  44.         instantiatedPlant.transform.parent = gameObject.transform;
  45.  
  46.         // Make the plant's position in the middle of the soil
  47.         Vector3 plantPosition = Vector3.zero;
  48.         plantPosition.y = 0f;
  49.         instantiatedPlant.transform.localPosition = plantPosition;
  50.  
  51.         // Set reference to the plant
  52.         currentPlant = instantiatedPlant.GetComponent<Plant>();
  53.  
  54.         // Set Planting Day
  55.         currentPlant.dayOfPlanting = TimeManager.Instance.dayInGame;
  56.     }
  57.  
  58.     internal void MakeSoilWatered()
  59.     {
  60.         GetComponent<Renderer>().material = wateredMaterial;
  61.     }
  62.  
  63.     internal void MakeSoilNotWatered()
  64.     {
  65.         GetComponent<Renderer>().material = defaultMaterial;
  66.     }
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement