// Update is called once per frame void Update() { if (!isPlaced && !isSnapped) { //maybe a virer BuildingManager.isBuilding = true; if (Physics.Raycast(cam.transform.position, cam.transform.TransformDirection(Vector3.forward), out hit, 20)) { if (hit.transform != this.transform) { currentPosition = new Vector3(hit.point.x, hit.point.y, hit.point.z); this.transform.position = currentPosition; } } } //Si on clique sur le bouton de la souris on pose l'objet if (Input.GetMouseButtonDown(0)) { isPlaced = true; craft_Book.delete_Ingredient(); craft_Book.clear_Inventaire(); BuildingManager.object_Actual = null; BuildingManager.isBuilding = false; this.GetComponent <Renderer>().material = material_Foundation; this.enabled = false; } //Retire le snap si on s'éloigne trop de l'objet if (isSnapped && !isPlaced && (Mathf.Abs(mousePosX - Input.GetAxis("Mouse X")) > 0.2f || Mathf.Abs(mousePosY - Input.GetAxis("Mouse Y")) > 0.2f)) { isSnapped = false; } }
// Update is called once per frame void Update() { if (!isPlaced && !isSnapped) { //maybe a virer BuildingManager.isBuilding = true; if (Physics.Raycast(cam.transform.position, cam.transform.TransformDirection(Vector3.forward), out hit, 20, layerColliderWall)) { Debug.DrawRay(cam.transform.position, cam.transform.TransformDirection(Vector3.forward * 20), Color.yellow); if (hit.transform != this.transform) { currentPosition = new Vector3(hit.point.x, hit.point.y, hit.point.z); this.transform.position = currentPosition; } } } //Si on clique sur le bouton de la souris on pose l'objet if (Input.GetMouseButtonDown(0) && isSnapped) { isPlaced = true; liste_Affichage_Collider = GameObject.FindGameObjectsWithTag("ColliderWall"); foreach (GameObject collider in liste_Affichage_Collider) { collider.GetComponent <Renderer>().enabled = false; } this.GetComponent <Renderer>().material = material_Wall; craft_Book.delete_Ingredient(); craft_Book.clear_Inventaire(); BuildingManager.object_Actual = null; BuildingManager.isBuilding = false; this.enabled = false; } if (Input.GetMouseButtonDown(1)) { if (this.transform.rotation.y != 90) { this.transform.Rotate(0, 90, 0); } else { this.transform.Rotate(0, 0, 0); } } //Retire le snap si on s'éloigne trop de l'objet if (isSnapped && !isPlaced && (Mathf.Abs(mousePosX - Input.GetAxis("Mouse X")) > 0.2f || Mathf.Abs(mousePosY - Input.GetAxis("Mouse Y")) > 0.5f)) { isSnapped = false; } }
// Update is called once per frame void Update() { if (!isPlaced) { if (Physics.Raycast(cam.transform.position, cam.transform.TransformDirection(Vector3.forward), out hit, 20, layer_Terrain)) { if (hit.transform != this.transform) { currentPosition = new Vector3(hit.point.x, hit.point.y, hit.point.z); this.transform.position = currentPosition; } } } if (Input.GetMouseButtonDown(0) && BuildingManager.isBuilding) { isPlaced = true; craft_Book.delete_Ingredient(); craft_Book.clear_Inventaire(); BuildingManager.object_Actual = null; BuildingManager.isBuilding = false; this.enabled = false; } }
// Update is called once per frame void Update() { if (!isPlaced && !isSnapped) { if (Physics.Raycast(cam.transform.position, cam.transform.TransformDirection(Vector3.forward), out hit, 20, layerColliderPilier)) { if (hit.transform != this.transform) { currentPosition = new Vector3(hit.point.x, hit.point.y, hit.point.z); this.transform.position = currentPosition; } } } //Si on clique sur le bouton de la souris on pose l'objet if (Input.GetMouseButtonDown(0) && isSnapped && BuildingManager.isBuilding) { liste_Affichage_Collider = GameObject.FindGameObjectsWithTag("ColliderPilier"); foreach (GameObject collider in liste_Affichage_Collider) { collider.GetComponent <Renderer>().enabled = false; } isPlaced = true; craft_Book.delete_Ingredient(); craft_Book.clear_Inventaire(); BuildingManager.object_Actual = null; this.GetComponent <Renderer>().material = material_Pilier; BuildingManager.isBuilding = false; this.enabled = false; } //Retire le snap si on s'éloigne trop de l'objet if (isSnapped && !isPlaced && (Mathf.Abs(mousePosX - Input.GetAxis("Mouse X")) > 2f || Mathf.Abs(mousePosY - Input.GetAxis("Mouse Y")) > 2f)) { Debug.Log(Mathf.Abs(mousePosX - Input.GetAxis("Mouse X"))); isSnapped = false; } }
public void craft_Item(string name_Item) { switch (name_Item) { case "Fondation": isBuilding = true; object_Actual = Instantiate(foundationPrefab, Vector3.zero, foundationPrefab.transform.rotation); break; case "Mur": isBuilding = true; object_Actual = Instantiate(wallPrefab, Vector3.zero, wallPrefab.transform.rotation); liste_Affichage_Collider = GameObject.FindGameObjectsWithTag("ColliderWall"); foreach (GameObject collider in liste_Affichage_Collider) { collider.GetComponent <Renderer>().enabled = true; collider.GetComponent <Renderer>().material = yellow_Color; } break; case "Pilier": Debug.Log("ok"); isBuilding = true; object_Actual = Instantiate(pilierPrefab, Vector3.zero, pilierPrefab.transform.rotation); liste_Affichage_Collider = GameObject.FindGameObjectsWithTag("ColliderPilier"); foreach (GameObject collider in liste_Affichage_Collider) { collider.GetComponent <Renderer>().enabled = true; collider.GetComponent <Renderer>().material = yellow_Color; } break; case "Porte": isBuilding = true; object_Actual = Instantiate(portePrefab, Vector3.zero, portePrefab.transform.rotation); break; case "Escalier": isBuilding = true; object_Actual = Instantiate(escalierPrefab, Vector3.zero, escalierPrefab.transform.rotation); break; case "Pioche": craft_Book.delete_Ingredient(); craft_Book.clear_Inventaire(); inventaire_Player.ajout_Outil_Inventaire("Pioche"); break; case "Hache": craft_Book.delete_Ingredient(); craft_Book.clear_Inventaire(); inventaire_Player.ajout_Outil_Inventaire("Hache"); break; case "Canne": craft_Book.delete_Ingredient(); craft_Book.clear_Inventaire(); inventaire_Player.ajout_Outil_Inventaire("Canne"); break; case "Piege": isBuilding = true; object_Actual = Instantiate(piegePrefab, Vector3.zero, piegePrefab.transform.rotation); object_Actual.name = "Viande_Crue"; break; case "Feu": isBuilding = true; object_Actual = Instantiate(feuPrefab, Vector3.zero, feuPrefab.transform.rotation); break; case "Lit": isBuilding = true; object_Actual = Instantiate(litPrefab, Vector3.zero, litPrefab.transform.rotation); break; case "Coffre": isBuilding = true; object_Actual = Instantiate(coffrePrefab, Vector3.zero, coffrePrefab.transform.rotation); break; case "Gourde": craft_Book.delete_Ingredient(); craft_Book.clear_Inventaire(); inventaire_Player.ajout_Outil_Inventaire("Gourde"); break; case "Houe": craft_Book.delete_Ingredient(); craft_Book.clear_Inventaire(); inventaire_Player.ajout_Outil_Inventaire("Houe"); break; } }