/// <summary> /// Setzt die Variable mit dem angegebenen namen auf den Defaultwert /// </summary> /// <param name="unitName">Name der Variable, die auf default gesetzt werden soll</param> public static void SetDefaultCharValueByName(string unitName) { if (PlayerScript.allies.Count == 0) { return; } if (unitName.Equals("puls") || unitName.Equals("kineticEnergy") || unitName.Equals("potentialEnergy") || unitName.Equals("time")) { return; } MovementScript.Properties props = PlayerScript.allies[0].GetComponent <GroupScript>().properties; if (unitName.Equals("force")) { props.GetType().GetField(unitName + "_x").SetValue(props, (float)defaultChar.GetType().GetField(unitName + "_x").GetValue(defaultChar));//reflection foreach (GameObject unit in PlayerScript.allies) { unit.GetComponent <GroupScript>().properties = props; Debug.Log("reflect: " + props.size); } props.GetType().GetField(unitName + "_y").SetValue(props, (float)defaultChar.GetType().GetField(unitName + "_y").GetValue(defaultChar));//reflection foreach (GameObject unit in PlayerScript.allies) { unit.GetComponent <GroupScript>().properties = props; Debug.Log("reflect: " + props.size); } return; } //Debug.Log(unitName); props.GetType().GetField(unitName).SetValue(props, (float)defaultChar.GetType().GetField(unitName).GetValue(defaultChar));//reflection foreach (GameObject unit in PlayerScript.allies) { unit.GetComponent <GroupScript>().properties = props; } }
//Constructor: public ObjectState(GameObject obj) { properties = DefaultStats.DeepClone(obj.GetComponent <ObjectScript>().properties); name = obj.GetComponent <SpriteRenderer>().sprite.name; position = new Vector2(obj.transform.position.x, obj.transform.position.y); rotation = obj.transform.rotation; scale = obj.transform.localScale; mass = obj.GetComponent <Rigidbody2D>().mass; }
public void CreateMenu() { if (block) { return; } block = true; Physics2D.autoSimulation = false; backupNames = new List <string>(PlayerScript.alliesNames); startPos = new List <Vector2>(); startAngle = new List <float>(); foreach (GameObject unit in PlayerScript.allies) { startPos.Add(unit.transform.position); startAngle.Add(unit.transform.eulerAngles.z); } if (GameObject.FindGameObjectWithTag("Player")) { pScript = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerScript>(); pScript.transform.GetChild(2).gameObject.SetActive(false); pScript.tag = "Ally"; } else { Debug.Log("Warnung: Player- Tag nicht gefunden. StartStats können abweichen"); } startStats = pScript.gScript.properties; GameManager.block = true; anim = GetComponent <Animator>(); Vector2 diff = -Vector2.one * Camera.main.orthographicSize - Vector2.up * 3; transform.position = (Vector2)Camera.main.transform.position + diff; gameObject.SetActive(true); sepLine = transform.Find("SeparationLine").gameObject; equalSign = transform.Find("EqualSign").gameObject; divideButton = transform.Find("DivideButton").gameObject; resetButton = transform.Find("ResetButton").gameObject; backButton = transform.Find("BackButton").gameObject; gegeben = transform.Find("Gegeben").gameObject; selection = transform.Find("Selection").gameObject; divisionLine = transform.Find("DivisionLine").gameObject; oneDivident = transform.Find("OneDivident").gameObject; oneDivisor = transform.Find("OneDivisor").gameObject; wrong = transform.Find("Wrong").gameObject; instructions = transform.Find("Instructions").gameObject; formulaButton = transform.Find("FormulaButton").gameObject; unitButton = transform.Find("UnitButton").gameObject; calcButton = transform.Find("CalcButton").gameObject; formulaList = transform.Find("FormulaList").gameObject; unitList = transform.Find("UnitList").gameObject; SetFormulaUI(false); formulaButton.SetActive(true); unitButton.SetActive(true); calcButton.SetActive(true); StartCoroutine(MenuCreation(diff: diff)); }