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?