Jump to content

I am trying to work my way through the tutorial games on the learn section of this. Right now I'm trying to complete the Survival Shooter game. In the tutorial video called player character it says to right Animator anim;

Which WONT work. It doesn't recognize it as a command. Here's my entire script. It's full of errors, even though I've checked letter for letter against the one in the "Completed Assets Folder"

Am I missing something? here's my entire script for PlayerMovement.cs

 

using UnityEngine;
using UnitySampleAssets.CrossPlatformInput;

public class PlayerMovement : MonoBehaviour
{
public float speed = 6f;

Vector3 movement;
Animator anim;
Rigidbody playerRigidbody;
int floorMask;
float camRayLength = 100f;

void Awake()
{
floorMask = LayerMask.GetMask("Floor")
anim = GetComponent <Animator> ();
playerRigidbody = GetComponent<Rigidbody>();
}

void FixedUpdate()
{
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");

move(h, v);
turning();
Animating(h, v);
}

void move(float h, float, v)
{
movement.Set(h, 0f, v);

movement = movement.normalized * speed * Time.deltaTime;

playerRigidbody.MovePosition(Transform.position + movement);

}

void turning()
{
Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);

RaycastHit floorhit;

if (Physics.Raycast(camRay, out floorhit, camRayLength, floorMask))
}
Vector3 playerToMouse = floorhit.point - Transform.position;
playerToMouse.y = 0f;

Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
playerRigidbody.MoveRotation (newRotation);

}
}


void Animating(float h, float v)
{
bool walking = h != 0f || v != 0f;
anim.SetBool("IsWalking".walking);
}



}

 

TX10 Build Log: http://linustechtips.com/main/topic/456229-tx10-build-log/

Case: TX10-D   Proccessor: i7-5820k   MotherBoard: Asrockx99 Extreme4   Ram: Crucial Ballistix Sport 16GB (DDR4-2400)   GPU: Asus Strix OC 980ti   Storage: 850pro 500gb, 850pro 500gb, 850pro 256gb, WD black 16tb total, Silicon Power S60 120GB   PSU: Seasonic snow silent 1050   Monitors: Three of Asus VG248QE 144Hz 24.0"

Link to comment
https://linustechtips.com/topic/647826-unity-scripting-problem/
Share on other sites

Link to post
Share on other sites

Does the object your script is applied to have an 'Animator' component? https://docs.unity3d.com/Manual/class-Animator.html

 

Also, you are missing a ; on the line "floorMask = LayerMask.GetMask("Floor")"

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
https://linustechtips.com/topic/647826-unity-scripting-problem/#findComment-8334055
Share on other sites

Link to post
Share on other sites

I know nothing about unity but I did a little .Net coding in school and other things
1. your number of { and } are not the same (used control+f)
2.check your using " ' correctly

3.check your using the right procedures for everything, sometimes two built in functions can do almost identical things but one might return the wrong variable type.

4. You may be better on a forum dedicated to unity?

Link to comment
https://linustechtips.com/topic/647826-unity-scripting-problem/#findComment-8334058
Share on other sites

Link to post
Share on other sites

4 minutes ago, Minibois said:

Does the object your script is applied to have an 'Animator' component? https://docs.unity3d.com/Manual/class-Animator.html

 

Also, you are missing a ; on the line "floorMask = LayerMask.GetMask("Floor")"

Yes it does, I'll fix the floormask and get back to you. thanks!

4 minutes ago, kris2340k said:

I know nothing about unity but I did a little .Net coding in school and other things
1. your number of { and } are not the same (used control+f)
2.check your using " ' correctly

3.check your using the right procedures for everything, sometimes two built in functions can do almost identical things but one might return the wrong variable type.

4. You may be better on a forum dedicated to unity?

I tried a dedicated unity forum but seeing the reply time from most of the topics assumed it would take a couple days. 

TX10 Build Log: http://linustechtips.com/main/topic/456229-tx10-build-log/

Case: TX10-D   Proccessor: i7-5820k   MotherBoard: Asrockx99 Extreme4   Ram: Crucial Ballistix Sport 16GB (DDR4-2400)   GPU: Asus Strix OC 980ti   Storage: 850pro 500gb, 850pro 500gb, 850pro 256gb, WD black 16tb total, Silicon Power S60 120GB   PSU: Seasonic snow silent 1050   Monitors: Three of Asus VG248QE 144Hz 24.0"

Link to comment
https://linustechtips.com/topic/647826-unity-scripting-problem/#findComment-8334082
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×