Example #1
0
 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;
             }
         }
     }
 }
Example #2
0
    void OnTriggerEnter(Collider collider)
    {
        IslandMesh mesh = collider.GetComponent <IslandMesh>();

        if (mesh != null && mesh.type == IslandMesh.MeshType.Water)
        {
            RecalculatePosition();
        }
    }
Example #3
0
    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();
            }
        }
    }
Example #4
0
    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);
    }
Example #5
0
    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();
                }
            }
        }
    }
Example #6
0
 void Start()
 {
     islandMesh = GetComponent <IslandMesh>();
     GenData();
 }
Example #7
0
 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;
 }