private void InitializeLevel() { gameManager = GameObject.Find("GameManager").GetComponent <GameManager>(); //Set Player to spawn point Vector2 position = new Vector2(spawn.position.x, spawn.position.y + 0.5f); player.transform.position = position; //Load unimog prefab GameObject obj = Instantiate(Resources.Load("Prefabs/Vehicles/" + gameManager.GetUnimogPrefabPath(), typeof(GameObject)), player.transform) as GameObject; CarAttributes carAttribs = obj.GetComponent <CarAttributes>(); //spawn boxes on cargoCheck Transform cargoCheck = GameObject.Find("cargoCheck").GetComponent <Transform>(); for (int i = 0; i < 2; i++) // amount of boxes from JSON { GameObject box = Instantiate(Resources.Load("Prefabs/Objects/Box"), new Vector3(cargoCheck.position.x, cargoCheck.position.y + 0.5f, cargoCheck.position.z), Quaternion.identity) as GameObject; } //Load level informations currentLevel = new Level(gameManager.GetSceneId()); gamePlayState = new GamePlayState(this, currentLevel, carAttribs, victoryScreen, gameOverScreen); SetCountdownState(); }
public CarAttributes ConvertBackToObject(string path) // when we need the car att back { string data = File.ReadAllText(path); CarAttributes Car = JsonUtility.FromJson <CarAttributes>(data); return(Car); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Player")) { CarAttributes ca = GameObject.Find("Player").GetComponentInChildren <CarAttributes>(); ca.SetCanDriveStatus(false); } }
public GamePlayState(Game game, Level level, CarAttributes carAttribs, VictoryScreen victoryScreen, GameOverScreen gameOverScreen) : base(game) { this.level = level; this.carAttributes = carAttribs; this.victoryScreen = victoryScreen; this.gameOverScreen = gameOverScreen; Initialize(); }
void FixedUpdate() { tippedOver = false; grounded = false; Collider2D[] colliders = Physics2D.OverlapCircleAll(groundCheck.position, groundedRadius, whatIsGround); for (int i = 0; i < colliders.Length; i++) { if (colliders[i].gameObject != gameObject) { grounded = true; } } tippedOver = this.ceilingCheck.GetComponent <Collider2D>().IsTouchingLayers(whatIsGround); if (tippedOver) { gameOverCounter += Time.fixedDeltaTime; if (gameOverCounter >= 1f) //anzahl Sekunden, die der Collider den Boden berühren soll { CarAttributes ca = this.GetComponentInParent <CarAttributes>(); ca.SetTippedOver(tippedOver); } } else { gameOverCounter = 0; if (movement == 0f || tippedOver || !carAttributes.GetCanDriveStatus()) { backWheel.useMotor = false; frontWheel.useMotor = false; } else if (grounded && !tippedOver && carAttributes.GetCanDriveStatus()) { backWheel.useMotor = true; frontWheel.useMotor = true; this.motor.motorSpeed = movement * driveSpeed; backWheel.motor = motor; frontWheel.motor = motor; carAttributes.ConsumeFuel(); } rb.AddTorque(-rotation * rotationSpeed * Time.fixedDeltaTime); } }
void InitCars() { StreamReader sr = new StreamReader(Path.Combine(PlayerPrefs.GetString("FolderPath"), "CarInput.txt")); string carInput = sr.ReadToEnd(); sr.Close(); string[] tempString = carInput.Split('#'); carsAttributes = new CarAttributes[tempString.Length]; for (int i = 1; i < tempString.Length; i++) { cameraSelectingDropDown.AddOptions(new List <string>(1) { "Car" + i.ToString() }); carsAttributes[i] = new CarAttributes(tempString[i]); StartCoroutine(CarSimulator(i)); } }
void Start() { //Unimog registers itself to Camera CMcam = GameObject.Find("CM vcam1").GetComponent <CinemachineVirtualCamera>(); CMcam.m_Follow = this.transform; CMcam.m_LookAt = this.transform; //Unimog uses Joystick joystick = GameObject.Find("drive_joystick").GetComponent <FixedJoystick>(); //Initialize Motor this.motor = new JointMotor2D { motorSpeed = 0, maxMotorTorque = torque }; //CarAttributes this.carAttributes = GetComponent <CarAttributes>(); player = GetComponentInParent <Player>(); }
public static void Write(float Shield, float MaxSpeed, float MaxAcceleration) //get all the players attributes and make a new car attributes object { #if UNITY_EDITOR path = Application.streamingAssetsPath + "/Resources/CarChoice.json"; #elif UNITY_ANDROID path = "jar:file://" + Application.dataPath + "!/Resources/CarChoice.json"; #endif #if UNITY_STANDALONE_WIN path = Application.streamingAssetsPath + "/Resources/CarChoice.json"; #endif CarAttributes Choice = new CarAttributes("Player", MaxAcceleration, Shield, MaxSpeed); StreamWriter writer = new StreamWriter(path, false); string json = JsonUtility.ToJson(Choice); //convert to a json object and write to file writer.Write(json); writer.Close(); }