I have an issue with the waypoints script that I am trying to convert from JS to C#. I have the code portion.
foreach (WayPoints cur in currentWaypoint.connected)
And I get the error:
`WayPoints.connected’ is inaccessible due to its protection level
Why is that? Now here is the entire code block I just wanted to point out that line.
public WayPoints PickedNextWaypoint ( WayPoints currentWaypoint) {
// We want to find the waypoint where the character has to turn the least
// The direction in which we are walking
Vector3 forward = transform.TransformDirection(Vector3.forward);
// The closer two vectors, the larger the dot product will be.
WayPoints best = currentWaypoint;
float bestDot = -10.0f;
foreach (WayPoints cur in currentWaypoint.connected) {
float direction = Vector3.Normalize(cur.transform.position - transform.position);
float dot = Vector3.Dot(direction, forward);
if (dot > bestDot cur != currentWaypoint) {
bestDot = dot;
best = cur;
}
}
return best;
}
Second small question how would you modify Array.length to be used with ArrayList because length is not a member of the ArrayList.
Thanks for the tips and the quick response. I found the length which I am assuming it is the .count. I am looking into the other part of the problem also but I am just not seeing it for some reason.
I am still stuck on this one, I got rid of the error by doing an arraylist but I don’t think that it is correct and then I did some mod on the code to get it to try and work.
This doesn’t work in C# but it does in JS what would be the equivalent for JS.
Source of the script is the FPS AI script. I get this error.
WayPoints.FindClosest(UnityEngine.Vector3)': An object reference is required for the nonstatic field, method or property
I am trying to be as detailed as possible so everyone could see it just in case they might have the same issue.
So would this be wrong code what I am doing or would this be the correct code for getting the object that is suppose to be the instance:
WayPoints curWayPoint = GetComponent<WayPoints>();
curWayPoint.FindClosest(transform.position);
while(true){
Debug.Log("We are on Patrol");
Vector3 waypointPosition = curWayPoint.transform.position;
//are we close to a waypointPosition
if(Vector3.Distance(waypointPosition, transform.position) < pickNextWaypointDistance)
curWayPoint = PickedNextWaypoint(curWayPoint);
//attack and wait until one of two things happen
//player is killed or out of sight
if(CanSeeTarget())
StartCoroutine("AttackPlayer");
//move towards the target
MoveTowards(waypointPosition);
Well I guess that I will keep asking to see if I could get some help maybe no one really knows the answer and if not then I know what I need to do but until then could someone help me with this issue. I keep using this code and getting the same error.
Now I am calling the script for the waypoints and calling the function for findclosest but I am steadily getting the same error message any more ideas on why?
You will get the null reference error if there is no script called WayPoints.cs attached to the current object (and it must also define a class called WayPoints derived from MonoBehaviour). Are the scripts you are using publicly available anywhere? If so, please can you post a link to them and if not please post the current script in full and also the WayPoints script.
I having trouble now with adding a script I am getting the error message about compile errors but I can’t none of my scripts in the component menu and they don’t have compile errors.
Ok so I put the ai from the JS and with the waypoints script it follows it nicely but when it is converted to c# I have all kinds of issues even though the syntax is correct does anyone have an idea? :?:
Got the script portion almost resolved there are no more errors. If any in interested the one thing that I had forgot was to do the addcomponent method in Unity aka the New Component in c#; http://msdn.microsoft.com/en-us/library/s35hcfh7(VS.80).aspx
Dude this is crazy, since Unity doesn’t like the new on a mono behaviour I added add component but now the ai doesn’t move to the the next way point it stays in one place in Idle.
Ok so I got rid of my errors but I am still stuck on the waypoints that are not being found because I am getting the null reference exception. So the question becomes how do I get rid of it if my objects are there but the script or whatever the case may be can’t find it?
You post things on the forum to get help and I had two people help me, I am not upset to the point where I want to alienate the community but just to put it out there that people are looking for help when they post on the forums not just to mess around all the time.
Here are the better scripts there is room for improvement so if you could do it better than be my guest I could use the help. :lol: