- Home /
How do I replace "SetVertexCount"?
Lucky me bought "Introduction to Game Design, Prototyping and Development" days before the second edition was published, now I'm stuck with outdated code. It hasn't been that bad so far and I've been able to solve some things but there's a problem I've tried to get around but I just can't. The webpage for the book made some update to the code but there's no guide to solving this:
There's a part where SetVertexCount is needed but it is now obsolete and it asks me to use numPositions. I tried to use it but it says it isn't a method. There is another post here where someone had this problem and the answer was very rude. I'm just getting into C# so I would really thank anyone who can help me with this. This is the entire script:
public float minDist = 0.1f;
public bool ____________________;
public LineRenderer line;
public GameObject _poi;
public List<Vector3> points;
void Awake () {
S = this;
//Get a reference to the LineRenderer
line = GetComponent<LineRenderer>();
//Disable it until its needed
line.enabled = false;
//Initialize the points List
points = new List<Vector3>();
}
//This is a property (method masquerading as a field)
public GameObject poi {
get {
return(_poi);
}
set {
_poi = value;
if (_poi != null) {
//When _poi is set to something new, it resets everything
line.enabled = false;
points = new List<Vector3> ();
AddPoint ();
}
}
}
//This can be used to clear the line directly
public void Clear() {
_poi = null;
line.enabled = false;
points = new List<Vector3> ();
}
public void AddPoint(){
//This is called to add a point to the line
Vector3 pt = _poi.transform.position;
if (points.Count > 0 && (pt - lastPoint).magnitude < minDist) {
// If the point isn't far enough from thelast point, it returns
return;
}
if (points.Count == 0) {
//If this is the launch point...
Vector3 launchPos = Slingshot.S.launchPoint.transform.position;
Vector3 launchPosDiff = pt - launchPos;
// ...it adds an extra bit of line to aid aiming later
points.Add (pt + launchPosDiff);
points.Add (pt);
line.SetVertexCount (2);
//Sets the first two points
line.SetPosition (0, points [0]);
line.SetPosition (1, points [1]);
//Enables the LineRenderer
line.enabled = true;
} else {
//Normal behavior of adding a point
points.Add (pt);
line.SetVertexCount (points.Count);
line.SetPosition (points.Count - 1, lastPoint);
line.enabled = true;
}
}
//Returns the location of the most recently added point
public Vector3 lastPoint {
get {
if (points == null) {
// If there are no points, returns Vector3.zero
return (Vector3.zero);
}
return (points [points.Count - 1]);
}
}
void FixedUpdate () {
if (poi == null) {
//If there is no poi, search for one
if (FollowCam.S.poi != null) {
if (FollowCam.S.poi.tag == "Projectile") {
poi = FollowCam.S.poi;
} else {
return; // Return if we didn't find a poi
}
} else {
return; //Return if we didn't find a poi
}
}
// If there is a poi, it's loc is added every FixedUpdate
AddPoint();
if (poi.GetComponent<Rigidbody> ().IsSleeping ()) {
//Once the poi is sleeping, it is cleared
poi = null;
}
}
Answer by MaxGuernseyIII · Sep 28, 2017 at 12:30 AM
Heh. numPositions is also obsolete. Anyway, you want the property positionCount, I think.
line.positionCount = 2;
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How can I animate linerenderer lines over time ? 1 Answer
What happened to Line Renderer! 1 Answer