- Home /
Tower defense blender grated tower get wird when i use destroy
Hi! I am working on a tower defense game and have only used cubes in unity as my tower. Now when I created a tower in the blender and use it in unity so is that weird when i use destroy(). So I have it now when I press the mouse so do i creates a tower transparent and you can move it where you want it and then press again on the mouse and it "builds". But as I have it now that you have the tower in transparent mode, you can press the right mouse button then it should remove the tower. But what is happening now is that when I do it so rotates my whole game plan on strange things hapend? This e code someone who has a clue what it could be? Only hapend when useing blender crated tower using UnityEngine; using System.Collections;
public class ByggTornVidKlick : MonoBehaviour {
public tornväljaren towerSelector;
private Vector3 temp;
public Camera mainCamera;
public static bool DoBuild;
private bool IsBuild;
GameObject Transparent;
private GameObject Tower;
public GameObject Player;
void Start()
{
DoBuild = false;
IsBuild = true;
}
void Update ()
{
if (EnergyManager.energy >= towerSelector.GetSelectedTowerCost ()) {
if (Input.GetButtonDown ("Fire1") && !Input.GetButton ("Ctrl")) {
Tower = towerSelector.getSelectedTower ();
if (!DoBuild && IsBuild) {
DoBuild = true;
ShowTransparent ();
IsBuild = false;
} else {
Build ();
DoBuild = false;
}
}
if (Transparent){
Transparent.transform.rotation = Tower.transform.localRotation;
}
if (Input.GetButtonDown ("Fire2"))
{
DoBuild = false;
IsBuild = true;
if(Transparent)
{
if(Transparent.gameObject.tag == "Tower")
{
Destroy(Transparent.gameObject);
Transparent = gameObject;
}
}
}
}
}
void ChangeAlpha(GameObject Piece, float Alpha)
{
Color TempColor = Piece.renderer.material.color;
TempColor.a = Alpha;
Piece.renderer.material.SetColor("_Color", TempColor);
}
//GameObject Transparent;
void ShowTransparent()
{
Vector3 playerPos = Player.transform.position;
playerPos -= 0.5f * Player.transform.up;
playerPos += 4 * Player.transform.forward;
Transparent = Instantiate(Tower, playerPos, Tower.transform.localRotation)as GameObject;
ChangeAlpha(Transparent, 0.4f);
Transparent.transform.parent = Player.transform;
if(Transparent.GetComponent<grundtornAi> ())
{
Transparent.GetComponent<grundtornAi> ().enabled = false;
}
if(Transparent.GetComponent<MortarTower> ())
{
Transparent.GetComponent<MortarTower> ().enabled = false;
}
}
void Build()
{
if (CollisionWhenBuildingTower.checkDoBuild) {
ChangeAlpha (Transparent, 10f);
Transparent.transform.parent = null;
IsBuild = true;
EnergyManager.energy -= towerSelector.GetSelectedTowerCost ();
if(Transparent.GetComponent<grundtornAi> ())
{
Transparent.GetComponent<grundtornAi> ().enabled = true;
}
if(Transparent.GetComponent<MortarTower> ())
{
Transparent.GetComponent<MortarTower> ().enabled = true;
}
Transparent = null;
}
}
}
Answer by thelime · Jan 04, 2014 at 02:11 AM
i did find the sulotion now!!!
on line 40 i have
if (Transparent){
Transparent.transform.rotation = Tower.transform.localRotation;
}
and i needed to change it to
if (Transparent.gameObject.tag == "Tower"){
Transparent.transform.rotation = Tower.transform.localRotation;
}
Your answer
Follow this Question
Related Questions
destroying a unit and removing it from a list 2 Answers
Instantiating Objects 1 Answer
An another problem - Tower Defense GUI ver.2. 1 Answer
Tower Defense tpwers follow player untill i klick 1 Answer
My tower defense script fires too often 5 Answers