Hello!
I’ve got a problem.
I want a gameobject that gets hit and when fallen to the ground the player
will get 100 points.
this is my code:
**var points : int = 0;
var kubbRotation = Quaternion;
var guiScore : GUIText;
function Update ()
{
guiScore.text = "Score: ";
}
function OnCollisionEnter(col : Collision)
{
if(col.collider.name == "Pinne(Clone)")
{
print(col.collider.name + " is hit");
if(gameObject.transform.localEulerAngles.x >= 80.0 gameObject.transform.localEulerAngles.x <= 270.0
|| gameObject.transform.localEulerAngles.y >= 80.0 gameObject.transform.localEulerAngles.y <= 270.0
|| gameObject.transform.localEulerAngles.z >= 80.0 gameObject.transform.localEulerAngles.z <= 270.0)
{
points += 100;
guiScore.text = "Score: " + points;
print("Score: " + points);
}
}
}**
So when my Pinne(Clone) hits the gameObject, let’s call it “Pelle”, it says that it’s hitted by Pinne(Clone) and everything is good. But when “Pelle” is on the ground and its rotation axis is greater or equal to 90 the player sometimes get points and sometimes they don’t.
I have tried to replace the second if to a while loop.
Can anyone help me?
use a debug on your angles to see what they are when you hit.
Well i did that and i saw:
Y = 132.8722
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
Points:OnCollisionEnter(Collision) (at Assets\Points.js:17)
In my code I have put that all angles between 80 and 270 should give 100 points… So I should have gotten a point…
Give the following a shot and see if it makes any difference.
if((gameObject.transform.localEulerAngles.x >= 80.0 gameObject.transform.localEulerAngles.x <= 270.0) || (gameObject.transform.localEulerAngles.y >= 80.0 gameObject.transform.localEulerAngles.y <= 270.0)|| (gameObject.transform.localEulerAngles.z >= 80.0 gameObject.transform.localEulerAngles.z <= 270.0))
lorenalexm:
Give the following a shot and see if it makes any difference.
if((gameObject.transform.localEulerAngles.x >= 80.0 gameObject.transform.localEulerAngles.x <= 270.0) || (gameObject.transform.localEulerAngles.y >= 80.0 gameObject.transform.localEulerAngles.y <= 270.0)|| (gameObject.transform.localEulerAngles.z >= 80.0 gameObject.transform.localEulerAngles.z <= 270.0))
both my Y and Z was between 80 and 270, still no point…
Y = 149.5802
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
Points:OnCollisionEnter(Collision) (at Assets\Points.js:17)
(Filename: Assets/Points.js Line: 17)
Z = 191.2619
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
Points:OnCollisionEnter(Collision) (at Assets\Points.js:18)
(Filename: Assets/Points.js Line: 18)
Any idea?