hi everyone, this is my 1st post since im very new to unity and coding in general. im creating this simple rts game but i cant get the buildings to rotate before i place them…not sure what im doing wrong but im sure its something very simple. please help iv been searching endlessly…here is my building placement code…
using UnityEngine;
using System.Collections;
public class BuildingPlacement : MonoBehaviour {
private Transform currentBuilding;
private bool hasplaced;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (currentBuilding != null && !hasplaced) {
Vector3 n = Input.mousePosition;
n = new Vector3 (n.x, n.y, transform.position.y);
Vector3 p = GetComponent ().ScreenToWorldPoint (n);
currentBuilding.position = new Vector3 (p.x, 0, p.z);
if (Input.GetMouseButtonDown (0)) {
if (IsLegalPosition()){
hasplaced = true;
}
if (Input.GetMouseButtonUp(1)){
Destroy(this.gameObject);
}
}
}
}
bool IsLegalPosition(){
return true;
}
public void SetItem(GameObject b){
hasplaced = false;
currentBuilding = ((GameObject)Instantiate(b)).transform;
}
}
and this is the rotation code im trying to attach to the buildings…
using UnityEngine;
using System.Collections;
public class Rotate : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
ApplyRotation ();
}
void ApplyRotation()
{
float deadZone = 0.01f;
float ease = 3500f;
float scrollWheelValue = Input.GetAxis (“Mouse ScrollWheel”) * ease * Time.deltaTime;
if ((scrollWheelValue > -deadZone && scrollWheelValue < deadZone) || scrollWheelValue == 0f)
return;
this.transform.eulerAngles = new Vector3 (transform.eulerAngles.x, transform.eulerAngles.y + scrollWheelValue, transform.eulerAngles.z);
}
}