Question by
ExpiditionVortex · Jun 09, 2018 at 07:19 AM ·
unity 2dvisual studiomonobehaviourintellisense
Can't seem to get Mono behavior to work
Hello! First time posting on Unity forums! I can't seem to get monobehavior or intelligent to work in visual studio. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public Rigidbody2D actingCharacterRigidbody;
private float playerSpeed = 3f; // Float variable that holds the player's speed.
private bool movementLocked; // Boolean variable that represents whether the player's WASD movement is locked or not.
// Use this for initialization
private void Start ()
{
movementLocked = false;
}
// Update is called once per frame
private void Update ()
{
if (movementLocked) // If movementLocked equals true, lock the movement.
{
Debug.Log("Movement is locked.");
}
else
{
Movement();
}
}
private void Movement() // Houses the code for the player's movement.
{
if(Input.GetKey("w")) // If w is pressed the player moves forward.
{
actingCharacterRigidbody.transform.Translate(transform.up * (playerSpeed * Time.deltaTime), Space.World); // Moves the player forwards relative to the direction he / she is facing.
}
if(Input.GetKey("s"))
{
actingCharacterRigidbody.transform.Translate(-transform.up * (playerSpeed * Time.deltaTime), Space.World); // Moves the player backwards relative to the direction he / she is facing.
}
if(Input.GetKey("a"))
{
actingCharacterRigidbody.transform.Translate(-transform.right * (playerSpeed * Time.deltaTime, Space.World)); // Moves the player to the left relative to the direction he / she is facing.
}
if(Input.GetKey("d"))
{
actingCharacterRigidbody.transform.Translate(transform.right * (playerSpeed * Time.deltaTime, Space.World)); // Moves the player to the right relative to the direction he / she is facing.
}
}
private bool Sprint()
{
}
public void MovementKeyhole(bool val) // Keyhole function that takes a boolean variable that locks or unlocks the player's WASD movement.
{
movementLocked;
}
}
Here is a picture to go along with it.
I'm using VS 2017 Community and Unity 2018.1.1f1.
Thank you!
code.png
(34.9 kB)
Comment
Your answer
Follow this Question
Related Questions
assembly csharp error 0 Answers
Why is my DialogueBoxObject not recognizing its dialogue? 0 Answers
Why can't I export my game to windows? 0 Answers