Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by thelime · Jan 03, 2014 at 05:28 PM · destroyblendertower-defensetower defense

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;
                 }
         }
 
 
 
 
         }
 
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image thelime · Jan 04, 2014 at 01:31 AM 0
Share

Anyone that have any idea?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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;
                 }
 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges