Sorry if this is a dumb questions, just want to learn from the community and see what you guys and girls do.
As I said I’m new to unity and I was wondering if it is alright to reuse scripts from tutorials that I have modified into my own projects even though I didn’t really write it
Example…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovementScript : MonoBehaviour
{
public CharacterController controller;
public float speed = 12f;
public float gravity = -9.81f;
public float jumpHeight = 3f;
public float jumpWait = 1f;
//Jumping
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
Vector3 velocity;
bool isGrounded;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
controller.Move(velocity * Time.deltaTime);
//extra controls
//Sprint
if (Input.GetKeyDown(KeyCode.LeftShift) && isGrounded)
{
speed22();
}
else if(Input.GetKeyUp(KeyCode.LeftShift) && isGrounded)
{
speed12();
}
//slow down speed when in air
if (!isGrounded)
{
speed12();
}
else if(isGrounded && Input.GetKey(KeyCode.LeftShift))
{
speed22();
}
//Jump
if (Input.GetButtonDown("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
StartCoroutine(jumpPause(jumpWait));
}
velocity.y += gravity * Time.deltaTime;
}
IEnumerator jumpPause(float jumpTime)
{
isGrounded = false;
yield return new WaitForSeconds(jumpTime);
isGrounded = true;
}
void speed12()
{
speed = 12f;
}
void speed22()
{
speed = 22f;
}
}
Sorry if this is a dumb question, I’m new and young, wanting to learn but not wanting to learn the bad habits that’s all
Ps. Dunno if this is a issue but sorry about the grammar I’m not the best at English even tho I speak the damn thing.