Hi,
I’m totally new to this website and I hope this is the right place to post my difficulties. I’m following a unity tutorial where I’m writing a football game. The problem is the instructor is not always responsive and sometimes, some of the questions the students place are just not answered to. My question is in the description given. When I disable the characteristics below the ball and leave the correct one active, 2 balls persistently appear instead of one. I cannot continue with the course as the continuation is only possible if 1 ball appears without rolling. How can i fix this? I cannot insert the picture as there is a parsing problem. My file is .jpg.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameController : MonoBehaviour
{
[SerializeField]
GameObject ballPrefab;
/*
[SerializeField]
Rigidbody rb; */
[SerializeField]
float ballForce;
GameObject ballInstance;
Vector3 mouseStart;
Vector3 mouseEnd;
float minDragDistance = 15f;
float zDepth = 25f;
// Start is called before the first frame update
private void Awake()
{
}
void Start()
{
CreateBall ();
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0))
{
mouseStart = Input.mousePosition;
}
if (Input.GetMouseButtonUp(0))
{
mouseEnd = Input.mousePosition;
if(Vector3.Distance(mouseEnd,mouseStart) > minDragDistance)
{
//throw ball
Vector3 hitPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, zDepth);
hitPos = Camera.main.ScreenToWorldPoint(hitPos);
ballInstance.transform.LookAt(hitPos);
ballInstance.GetComponent<Rigidbody>().AddRelativeForce(Vector3.forward * ballForce, ForceMode.Impulse);
}
}
}
void CreateBall()
{
ballInstance = Instantiate(ballPrefab, ballPrefab.transform.position, Quaternion.identity) as GameObject;
}
}