I keep getting this error code and game wont play -the error code is-
“Assets/darts/CannonScript.cs(17,25): error CS0246: The type or namespace name `List’ could not be found. Are you missing a using directive or an assembly reference?” the code look good so whats going on? please help
using UnityEngine; using System.Collections; using System.Collections.Generic;
public class CannonScript : MonoBehaviour
{
// TrajectoryPoint and Ball will be instantiated
public GameObject TrajectoryPointPrefeb;
5. public GameObject BallPrefb;
private GameObject ball;
private bool isPressed, isBallThrown;
private float power = 25;
10. private int numOfTrajectoryPoints = 30;
private List trajectoryPoints;
//---------------------------------------
void Start ()
{
15. trajectoryPoints = new List();
isPressed = isBallThrown =false;
// TrajectoryPoints are instatiated
for(int i=0;i<numOfTrajectoryPoints;i++)
{
20. GameObject dot= (GameObject) Instantiate(TrajectoryPointPrefeb);
dot.renderer.enabled = false;
trajectoryPoints.Insert(i,dot);
}
}
25. //---------------------------------------
void Update ()
{
if(isBallThrown)
return;
30. if(Input.GetMouseButtonDown(0))
{
isPressed = true;
if(!ball)
createBall();
35. }
else if(Input.GetMouseButtonUp(0))
{
isPressed = false;
if(!isBallThrown)
40. {
throwBall();
}
}
// when mouse button is pressed, cannon is rotated as per mouse movement and projectile trajectory path is displayed.
45. if(isPressed)
{
Vector3 vel = GetForceFrom(ball.transform.position,Camera.main.ScreenToWorldPoint(Input.mousePosition));
float angle = Mathf.Atan2(vel.y,vel.x)* Mathf.Rad2Deg;
transform.eulerAngles = new Vector3(0,0,angle);
50. setTrajectoryPoints(transform.position, vel/ball.rigidbody.mass);
}
}
//---------------------------------------
// Following method creates new ball
55. //---------------------------------------
private void createBall()
{
ball = (GameObject) Instantiate(BallPrefb);
Vector3 pos = transform.position;
60. pos.z=1;
ball.transform.position = pos;
ball.SetActive(false);
}
//---------------------------------------
65. // Following method gives force to the ball
//---------------------------------------
private void throwBall()
{
ball.SetActive(true);
70. ball.rigidbody.useGravity = true;
ball.rigidbody.AddForce(GetForceFrom(ball.transform.position,Camera.main.ScreenToWorldPoint(Input.mousePosition)),ForceMode.Impulse);
isBallThrown = true;
}
//---------------------------------------
75. // Following method returns force by calculating distance between given two points
//---------------------------------------
private Vector2 GetForceFrom(Vector3 fromPos, Vector3 toPos)
{
return (new Vector2(toPos.x, toPos.y) - new Vector2(fromPos.x, fromPos.y))*power;
80. }
//---------------------------------------
// Following method displays projectile trajectory path. It takes two arguments, start position of object(ball) and initial velocity of object(ball).
//---------------------------------------
void setTrajectoryPoints(Vector3 pStartPosition , Vector3 pVelocity )
85. {
float velocity = Mathf.Sqrt((pVelocity.x * pVelocity.x) + (pVelocity.y * pVelocity.y));
float angle = Mathf.Rad2Deg*(Mathf.Atan2(pVelocity.y , pVelocity.x));
float fTime = 0;
90. fTime += 0.1f;
for (int i = 0 ; i < numOfTrajectoryPoints ; i++)
{
float dx = velocity * fTime * Mathf.Cos(angle * Mathf.Deg2Rad);
float dy = velocity * fTime * Mathf.Sin(angle * Mathf.Deg2Rad) - (Physics2D.gravity.magnitude * fTime * fTime / 2.0f);
95. Vector3 pos = new Vector3(pStartPosition.x + dx , pStartPosition.y + dy ,2);
trajectoryPoints*.transform.position = pos;*
trajectoryPoints*.renderer.enabled = true;*
trajectoryPoints_.transform.eulerAngles = new Vector3(0,0,Mathf.Atan2(pVelocity.y - (Physics.gravity.magnitude)fTime,pVelocity.x)Mathf.Rad2Deg);
fTime += 0.1f;
100. }
}
}_