You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.4 KiB
78 lines
2.4 KiB
using UnityEngine; |
|
|
|
public class GameStick : MonoBehaviour |
|
{ |
|
GameObject m_arrowObj = null; |
|
GameObject m_dotObj = null; |
|
float m_arrowSize = 289f - 118f - 59f; |
|
Vector3 m_dotDefaultPos = new Vector3(); |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void Start () |
|
{ |
|
Init(); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void Init() |
|
{ |
|
m_arrowObj = transform.Find("arrow").gameObject; |
|
m_dotObj = m_arrowObj.transform.Find("arrow").gameObject; |
|
m_dotDefaultPos = m_dotObj.transform.localPosition; |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public void SetDefault(bool isDefault) |
|
{ |
|
//Vector3 scale = m_arrowObj.transform.localScale; |
|
if (isDefault) |
|
{ |
|
SetArrowAngle(0); |
|
m_dotObj.transform.localPosition = m_dotDefaultPos; |
|
} |
|
|
|
//m_arrowObj.transform.localScale = scale; |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public float GetArrowYScale() |
|
{ |
|
Vector3 arrowScale = m_arrowObj.transform.localScale; |
|
return arrowScale.y; |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public void SetArrowScale(float delta) |
|
{ |
|
float neededYScale = delta / m_arrowSize; |
|
if (neededYScale > 1f) |
|
neededYScale = 1f; |
|
|
|
float dotShift = m_arrowSize * neededYScale; |
|
|
|
Vector3 dotPos = m_dotObj.transform.localPosition; |
|
dotPos.y = dotShift; |
|
m_dotObj.transform.localPosition = dotPos; |
|
//Vector3 arrowScale = m_arrowObj.transform.localScale; |
|
//arrowScale.y = neededYScale; |
|
//m_arrowObj.transform.localScale = arrowScale; |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public void UpdateArrow(Vector3 dir) |
|
{ |
|
float angle = Vector3.Angle(dir, new Vector3(0, 1, 0)); |
|
if (dir.x > 0) |
|
angle = -angle; |
|
|
|
SetArrowAngle(angle); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void SetArrowAngle(float angle) |
|
{ |
|
Vector3 arrowAngle = m_arrowObj.transform.eulerAngles; |
|
arrowAngle.z = angle; |
|
m_arrowObj.transform.eulerAngles = arrowAngle; |
|
} |
|
}
|
|
|