Beispiel #1
0
 public void initialize(VoxelData voxelData, BlobManager blobOwner, IntVector3 startPosition)
 {
     this.blobOwner = blobOwner;
     this.startPosition = startPosition;
     textureIndex = 0;
     status = new VoxelStatus ();
     setVoxelData (voxelData);
     setName ();
 }
Beispiel #2
0
    public void CreateVoxelGameObject(float voxelSize, float margin, Vector3Int gridDimension, Vector3 startingPoint)
    {
        _goVoxel      = GameObject.CreatePrimitive(PrimitiveType.Cube);
        _goVoxel.name = $"Voxel {Index}";
        _goVoxel.tag  = "Voxel";
        _goVoxel.transform.localScale = Vector3.one * voxelSize;

        _goVoxel.transform.position = startingPoint + (Vector3)Index * (voxelSize + margin);
        Status       = _goVoxel.AddComponent <VoxelStatus>();
        Status.Alive = false;
        Status.Daddy = this;
    }
    public Voxel(Vector3Int index, float voxelSize, float margin)
    {
        Index        = index;
        GOVoxel      = GameObject.CreatePrimitive(PrimitiveType.Cube);
        GOVoxel.name = $"Voxel {Index}";
        GOVoxel.tag  = "Voxel";
        GOVoxel.transform.localScale = Vector3.one * voxelSize;

        GOVoxel.transform.position = (Vector3)Index * (voxelSize + margin);
        _rigidBody             = GOVoxel.AddComponent <Rigidbody>();
        _rigidBody.mass        = _mass;
        _rigidBody.isKinematic = true;

        Status       = GOVoxel.AddComponent <VoxelStatus>();
        Status.Alive = true;
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                // the object identified by hit.transform was clicked
                // do whatever you want
                if (hit.transform.tag == "Voxel")
                {
                    VoxelStatus status = hit.transform.gameObject.GetComponent <VoxelStatus>();
                    _grid.SetClickable(_add);

                    if (status.Alive != _add)
                    {
                        status.Alive = !status.Alive;
                    }
                }
            }
        }
    }