Hi, my unity 2018.2.14f1 not finding game object, i dont know whats wrong with it, Code is below
i have tried it with FindWithTag,FindGameObjectWithTag too, this prefab has name Ball and the tag too, whats wrong with it? can anyone please help me. if I make it public, and drop prefab manually, it works fine, but not finding it.
public class Projectile : MonoBehaviour
{
public Transform target;
public Transform throwPoint;
private GameObject FireBall;
public float timeTillHit = 1f;
public Slider AngleSlider;
void Start ()
{
FireBall = GameObject.Find ("Ball");
}
public void FireTheBall ()
{
float xdistance;
xdistance = target.position.x - throwPoint.position.x;
float ydistance;
ydistance = target.position.y - throwPoint.position.y;
float throwAngle; // in radian
//OLD
//throwAngle = Mathf.Atan ((ydistance + 4.905f) / xdistance);
//UPDATED
throwAngle = Mathf.Atan ((ydistance + 4.905f * (timeTillHit * timeTillHit)) / xdistance);
//OLD
//float totalVelo = xdistance / Mathf.Cos(throwAngle) ;
//UPDATED
float totalValue = xdistance / (Mathf.Cos (throwAngle) * timeTillHit);
float xValue, yValue;
xValue = totalValue * Mathf.Cos (throwAngle);
yValue = totalValue * Mathf.Sin (throwAngle);
if (FireBall == null) {
FireBall = GameObject.Find ("Ball");
}
GameObject bulletInstance = Instantiate (FireBall, throwPoint.position, Quaternion.Euler (new Vector3 (0, 0, 0))) as GameObject;
Rigidbody2D rb;
rb = bulletInstance.GetComponent<Rigidbody2D> ();
rb.velocity = new Vector2 (xValue, yValue);
}
public void MoveTarget ()
{
target.position = new Vector3 (0f, (float)AngleSlider.value);
}
}
//END-Class