Beispiel #1
0
        public bool RemoveTower()
        {
            // We can't do anything if there's nothing to remove
            if (attachedTower == null)
            {
                return(false);
            }

            // Free the position and rotation of the tower
            attachedTower.GetComponent <Rigidbody>().detectCollisions = towerRigidWasColliding;
            attachedTower.GetComponent <Rigidbody>().isKinematic      = towerRigidWasKinematic;

            // Change the material to indicate that this position is now open
            GetComponent <Renderer>().material = openHoverMat;

            // Clear the HUD text
            if (hudText != null)
            {
                hudText.text = "";
            }

            // Restore the tower object and destroy the tower dive components
            attachedTower.DestroyTowerComponents();
            attachedTower.ShowTowerObject();

            // Clear the reference to the attached tower;
            attachedTower = null;

            return(true);
        }
Beispiel #2
0
        public void AttachTower(TowerObject tower, Vector3 positionOFfset, Vector3 rotationOffset)
        {
            // Fix the tower to the position and rotation of the node
            Vector3    newPos = transform.position + positionOFfset;
            Quaternion newRot = transform.rotation /* Quaternion.Euler(rotationOffset)*/;

            tower.transform.SetPositionAndRotation(newPos, newRot);
            tower.transform.Rotate(rotationOffset);
            print("applied rotation : " + rotationOffset);
            towerRigidWasColliding = tower.GetComponent <Rigidbody>().detectCollisions;
            towerRigidWasKinematic = tower.GetComponent <Rigidbody>().isKinematic;
            tower.GetComponent <Rigidbody>().detectCollisions = false;
            tower.GetComponent <Rigidbody>().isKinematic      = true;

            // Change the material to indicate that this position is now closed
            GetComponent <Renderer>().material = closedMat;

            // Set the HUD text
            if (hudText != null)
            {
                hudText.text = tower.towerName;
            }

            // Store a reference to the attached tower
            attachedTower = tower;

            tower.SpawnTowerComponents(this);
            tower.HideTowerObject();
        }