Implemented Inheritence

Co-Authored-By: ZeinabBF <145973209+ZeinabBF@users.noreply.github.com>
This commit is contained in:
Abdul Mukheem Shaik 2024-05-28 01:58:01 +02:00
parent 01e8803348
commit 08d350dd7c
2 changed files with 13 additions and 17 deletions
Assets
SharedSpatialAnchors/Scripts
Wind_Turbine/Scripts

@ -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)

@ -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);