My game script is fine but I'm still getting unexpected class error
I am working on a game in Unity and I've asked someone who is quite experienced who fixed the script for me but I'm still getting these errors. We've done just about everything and I've even updated and redownloaded Unity to try and fix this but the script is still showing me errors.
Here's a screenshot of the errors: http://sta.sh/026p1e3f8i5n
I tried writing a new script, typing in exactly what was in the previous script but still received the same errors plus some new ones as well: http://sta.sh/01mxp83amcng
My friend who is helping me isn't experiencing this problem and neither is their friend who tried it too so we're both pretty stuck on this problem. My computer is an MSI all-in-one Gaming touchscreen: http://www.cnet.com/au/products/msi-ag270/ and the system it's using is windows 8.1 My friend is also using windows 8.1 so that can't be the issue.
We would both greatly appreciate any advice about this as we can't figure out what the issue is. Here's a copy of the C# Script:
using UnityEngine; using System.Collections;
public class GamePlayer : MonoBehaviour {
private Animator anim;
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
private Animator anim;
// Use this for initialization
void Start () {
anim = gameObject.GetComponentInChildren<Animator> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKey ("w")) {
anim.SetInteger ("AnimPar", 1);
} else {
anim.SetInteger ("AnimPar", 0);
}
/*if (Input.GetKeyDown ("space")){
anim.SetInteger ("Jump");
} else {
anim.SetInteger ("Jump");
}*/
/* SetInteger won't work because the function is expecting an integer as the second input value
In the animator there are different params you can add:
Integer (int)
Float
Boolean (bool)
Trigger
Each has their repective functions:
SetInteger (paramName, int)
SetFloat (paramName, float)
SetBool (paramName, bool)
SetTrigger (paramName) -- this one has no second input
More animator functions: https://docs.unity3d.com/ScriptReference/Animator.html
You had it right, just you forgot to change the name of the function. But I think
I told you to turn it into a bool, so use SetBool. You may also need to add extra
code that handle your character touching the ground so that the jump can end.
*/
if (Input.GetKeyDown ("space")){
anim.SetBool ("Jump", true);
} // notice how i didn't add the second half of your original snippet
// If i left it, then your character would have transistioned to standing while in midair
// when you let go of spacebar, and you probably don't want that
// Goto OnCollisionEnter function to see the other half
}
//This function reads collisions made in game, specificialy only the frame in which the object just
//touched another object, hence on enter only.
void OnCollisionEnter(Collision collisionInfo) {
foreach (ContactPoint contact in collisionInfo.contacts) { //This just seperates contacts
if (Vector3.Angle(contact.normal, Vector3.up) < 45) { // This if statement checks if the platform it collided with is flat enough to stand on
// platforms that are less than a 45 degree angle incline will not let this part of the code run
anim.SetBool ("Jump", false); // If it is a "floor" then the jump animation will stop.
}
}
}
// make sure you have the transisions:
// Idle => Jump (Condition: "Jump" == true)
// Jump => Idle (Condition: "Jump" == false)
}