void Update() { if (attachedObject != null && (transform.parent == null || !transform.parent.Equals(attachedObject.transform))) { transform.parent = attachedObject.transform; } if (transform.parent != null) { transform.position = Vector3.Lerp(transform.position, transform.parent.position, 2f * Time.deltaTime); } rotation += new Vector3(0, Input.GetAxis("Horizontal"), 0) * Time.deltaTime * -55f; transform.localRotation = Quaternion.Slerp(transform.localRotation, Quaternion.Euler(rotation), 5f * Time.deltaTime); if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit[] hits; hits = Physics.RaycastAll(ray); foreach (RaycastHit hit in hits) { IslandMesh mesh = hit.collider.GetComponent <IslandMesh>(); if (mesh != null && mesh.type != IslandMesh.MeshType.Water) { GameObject obj = (GameObject)Instantiate(Resources.Load <GameObject>("P_Arrow"), hit.point + (Vector3.up * 0.3f), Quaternion.Euler(Vector3.down)); obj.transform.parent = mesh.island.transform; } } } }
void OnTriggerEnter(Collider collider) { IslandMesh mesh = collider.GetComponent <IslandMesh>(); if (mesh != null && mesh.type == IslandMesh.MeshType.Water) { RecalculatePosition(); } }
void OnCollisionEnter(Collision collision) { IslandMesh mesh = collision.collider.GetComponent <IslandMesh>(); if (mesh != null && mesh.type == IslandMesh.MeshType.Top) { if (collision.contacts[0].normal.y < 0.5f) { RecalculatePosition(); } } }
IslandMesh CreateIslandMesh(IslandMesh.MeshType type) { GameObject obj = new GameObject(name + "-" + type); obj.transform.parent = transform; IslandMesh mesh = obj.AddComponent <IslandMesh>(); mesh.island = this; mesh.type = type; mesh.Init(); mesh.BuildMesh(); return(mesh); }
public void RecalculatePosition() { transform.localPosition = new Vector3((float)(island.random.NextDouble() - 0.5) * (island.size / 1.5f), 9, (float)(island.random.NextDouble() - 0.5) * (island.size / 1.5f)); Ray ray = new Ray(transform.position, Vector3.down); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100f)) { IslandMesh islandMesh = hit.collider.gameObject.GetComponent <IslandMesh>(); if (islandMesh != null) { if (hit.normal.y < 0.5f || islandMesh.type == IslandMesh.MeshType.Water) { RecalculatePosition(); } } } }
void Start() { islandMesh = GetComponent <IslandMesh>(); GenData(); }
IslandMesh CreateIslandMesh(IslandMesh.MeshType type) { GameObject obj = new GameObject(name + "-" + type); obj.transform.parent = transform; IslandMesh mesh = obj.AddComponent<IslandMesh>(); mesh.island = this; mesh.type = type; mesh.Init(); mesh.BuildMesh(); return mesh; }