From 08d350dd7ca3d3fe3a2692d780d4cbc6e97886ba Mon Sep 17 00:00:00 2001 From: Abdul Mukheem Shaik <mukheemuddin@gmail.com> Date: Tue, 28 May 2024 01:58:01 +0200 Subject: [PATCH] Implemented Inheritence Co-Authored-By: ZeinabBF <145973209+ZeinabBF@users.noreply.github.com> --- Assets/SharedSpatialAnchors/Scripts/API.cs | 11 +++-------- Assets/Wind_Turbine/Scripts/Windturbine.cs | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Assets/SharedSpatialAnchors/Scripts/API.cs b/Assets/SharedSpatialAnchors/Scripts/API.cs index 7f97ace..54c00d0 100644 --- a/Assets/SharedSpatialAnchors/Scripts/API.cs +++ b/Assets/SharedSpatialAnchors/Scripts/API.cs @@ -58,9 +58,7 @@ public class API : MonoBehaviourPunCallbacks, IPunObservable private AudioController audioControllerScript; public bool turn_WT_on_Y_Axis = false; - public GameObject windTurbineWithMap; - private GameObject windTurbineController; - private Windturbine windTurbineControllerScript; + void Start() { @@ -70,8 +68,7 @@ public class API : MonoBehaviourPunCallbacks, IPunObservable photonView = PhotonView.Get(this); photonView.RPC("RPC_EmergencyButtonClick", RpcTarget.All); - windTurbineWithMap = GameObject.FindGameObjectWithTag("Wind_Turbine_withMap"); - + } void Update() @@ -182,8 +179,6 @@ public void ExtractDataFromJson(string json) Debug.Log("Latest WS is - "+latestWS); } } - windTurbineController = windTurbineWithMap.transform.GetChild(0).gameObject; - windTurbineControllerScript = windTurbineController.GetComponent<Windturbine>(); photonView = PhotonView.Get(this); photonView.RPC("RPC_GreenButtonClick", RpcTarget.All,windDirectionInDirectionTerms,LatestT+" C","Kista",latestWS+" m/s",true); } @@ -201,7 +196,7 @@ public void ExtractDataFromJson(string json) Debug.Log("Flag value to turn the Y Axis:" + turn_WT_on_Y_Axis); - windTurbineControllerScript.WT_TurnOnIts_Y_Axis(); + //windTurbineControllerScript.WT_TurnOnIts_Y_Axis(); } [PunRPC] public void RPC_VoltageUpdate(String voltageGenerated) diff --git a/Assets/Wind_Turbine/Scripts/Windturbine.cs b/Assets/Wind_Turbine/Scripts/Windturbine.cs index 3b4e31b..2bfdcf2 100644 --- a/Assets/Wind_Turbine/Scripts/Windturbine.cs +++ b/Assets/Wind_Turbine/Scripts/Windturbine.cs @@ -3,12 +3,12 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class Windturbine : MonoBehaviour +public class Windturbine : API { float angle; public float speed; - private API apiScript; - private GameObject GUIdataGameObject; + //private API apiScript; + //private GameObject GUIdataGameObject; PhotonView photonView; public float startRotationY = 0f; @@ -21,8 +21,8 @@ public class Windturbine : MonoBehaviour { angle = Random.Range(0.0f, 120.0f); speed = Random.Range(75.0f, 86.0f); - GUIdataGameObject = GameObject.FindGameObjectWithTag("GUIData"); - apiScript = GUIdataGameObject.GetComponent<API>(); + //GUIdataGameObject = GameObject.FindGameObjectWithTag("GUIData"); + //apiScript = GUIdataGameObject.GetComponent<API>(); //THis condition is to detach the map with the Wind turbine after Instantiating. This helps the map stick to the ground when the turbine rotates. GameObject.FindGameObjectWithTag("map").transform.SetParent(null); ; @@ -35,10 +35,10 @@ public class Windturbine : MonoBehaviour photonView = PhotonView.Get(this); photonView.RPC("RPC_WT_Turn", RpcTarget.All); - if(apiScript.turn_WT_on_Y_Axis) + if(turn_WT_on_Y_Axis) //From Base class { WT_TurnOnIts_Y_Axis(); - apiScript.turn_WT_on_Y_Axis = false; + turn_WT_on_Y_Axis = false; } } @@ -48,7 +48,7 @@ public class Windturbine : MonoBehaviour { //Debug.Log("WIND SPEED FROM API SCRIPT:" + apiScript.latestWS); transform.localEulerAngles = new Vector3(0.0f, 0.0f, angle); - angle += Time.deltaTime * (apiScript.latestWS * 10); // as the value we are fetching could not turn the blades completely, Multiplying the value we are fetching from API by 10. + angle += Time.deltaTime * (latestWS * 10); // as the value we are fetching could not turn the blades completely, Multiplying the value we are fetching from API by 10. } @@ -62,13 +62,14 @@ public class Windturbine : MonoBehaviour public void RPC_WT_TurnOnIts_Y_Axis() { Debug.Log("Rotate On it's Y-Axis"); - endRotationY = apiScript.latestWD; + endRotationY = latestWD; StartCoroutine(RotateObject(startRotationY, endRotationY, 3.5f)); } // Method to turn the 'Turbine' on its Y axis as per the DIRECTION of wind that is fetched from API IEnumerator RotateObject(float startAngle, float endAngle, float duration) { + Debug.Log("Rotate On it's Y-Axis- COROUTINE"); yield return new WaitForSeconds(2f); float timeElapsed = 0f; Quaternion startRotation = Quaternion.Euler(0, startAngle, 0);