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 02, 2014 at 03:17 AM · tower-defensetower defensespaw

Tower Defense tpwers follow player untill i klick

hi there! I'm into a Tower Defens games now and encountered a problem I do not have a clue how to solve: (. In my game running around in fps mode and where I press the mouse now "build" my tower. But I want that when I chose my tower as the player must see the tower on the ground 2-3 meters in front of him and it shall be transparant. and then when I press the mouse so must the tower be built on that spot that the player sees the transparent tower. Here is the code I have now

chosing tower using UnityEngine; using System.Collections;

 public class väljtornvidklick : MonoBehaviour {
 
 
     public GameObject towerSelector;
 
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     void Clicked()
     {
         // beräta för tornväljaren att ändra valt torn
         towerSelector.SendMessage ("SetSelectedTower", gameObject);
 
     }
 }

and here is the script for changing the tower enter code hereusing UnityEngine; using System.Collections;

 public class tornväljaren : MonoBehaviour {
 
     public GameObject[] towersIcons;
     public GameObject[] towers;
     public int[] towersCosts;
 
     public float towerIconRotaionRate = 01.0f;
 
     private int selectedTower = 0;
     // Use this for initialization
     void Start () 
     {
     
     }
     
     // Update is called once per frame
     void Update () 
     {
         towersIcons[selectedTower].transform.Rotate(Vector3.up, towerIconRotaionRate * Time.deltaTime);
 
     }
 
     public GameObject getSelectedTower()
     {
         return towers[selectedTower];
 
     }
     public int GetSelectedTowerCost()
     {
         return towersCosts [selectedTower];
 
 
     }
 
     void SetSelectedTower(GameObject inputTower)
     {
         int index = 0;
         foreach (GameObject towerIcon in towersIcons) 
         {            
             if (inputTower == towerIcon) 
             {
                 selectedTower = index;
             }
         index++;
         }
     }
 }



And finaly the script for building the towers using UnityEngine; using System.Collections;

 public class ByggTornVidKlick : MonoBehaviour {
 
 
 
     public tornväljaren towerSelector;
     private Vector3 temp;
     public Camera mainCamera;
 
     void Clicked(Vector3 position)
     {
         if (!Input.GetButton ("Ctrl")) 
         {
             if (EnergyManager.energy >= towerSelector.GetSelectedTowerCost ()) {
                 GameObject tower = towerSelector.getSelectedTower ();
                 Instantiate (tower, position + Vector3.up * 0.5f, tower.transform.rotation);
                 EnergyManager.energy -= towerSelector.GetSelectedTowerCost ();
             }
         }
     }
 
     void Update () 
     {
 
         }
 }


is there anyone who can help me?

Comment
Add comment · Show 2
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 robertbu · Jan 02, 2014 at 02:22 AM 0
Share

I don't see a clear question here. Are you asking someone to code a solution for you? That's not what UA is all about. UA is best at solving single, specific technical issue.

avatar image thelime · Jan 02, 2014 at 05:46 AM 0
Share

aa i am sorry! i do not whant someone to do the jobb for me i whanted a push so i can start. dident have any idea on how to solv the problem

1 Reply

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

Answer by sparkzbarca · Jan 02, 2014 at 03:27 AM

ill get ya started

 //first click shows the transparent object, second builds it, if you click once dobuild 
 //becomes true
 bool DoBuild;
 
 public GameObject Tower;
 
 void Start()
 {
 DoBuild = false;
 }
 
 Void Update()
 {
 
 
 if(input.getbuttondown("Build Tower")
 {
 if(!DoBuild)
 {
 DoBuild = true;
 ShowTransparent();
 }
 else
 {
 Build();
 Dobuild = false;
 }
 }
 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()
 {
 Transparent = Instantiate(Tower, player.transform.position + (2 * player.transform.forward), quanternion.identity);
 ChangeAlpha(Transparent, .5f);
 Transparent.transform.parent = player.transform;
 }
 
 void Build()
 {
 ChangeAlpha(Transparent, 1f);
 Transparent.transform.parent = null;
 }

this still needs ALOT

it needs the abillity to rotate the tower, needs a collision check to make sure it can be built where it is.

it spawns directly in front of the player without regard for the terrain height that needs solved.

It has many issues but its a good start.

Comment
Add comment · Show 2 · 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
avatar image thelime · Jan 02, 2014 at 05:48 AM 0
Share

aa thx this is whant i needed :). now i can start to work and change it so i can use it to my game and terrain :)

avatar image sparkzbarca · Jan 02, 2014 at 06:14 AM 0
Share

mark as answered :)

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

19 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 avatar image

Related Questions

An another problem - Tower Defense GUI ver.2. 1 Answer

What is the procedure of spawning enemies in each round ? TD games 1 Answer

Tower defense blender grated tower get wird when i use destroy 1 Answer

How to implement fast forward feature in a tower defense game? 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