Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created February 2, 2018 01:07
Show Gist options
  • Select an option

  • Save unity3dcollege/eba946b6fd75bbcbe81d05b04da778c1 to your computer and use it in GitHub Desktop.

Select an option

Save unity3dcollege/eba946b6fd75bbcbe81d05b04da778c1 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
private CharacterController characterController;
private Animator animator;
[SerializeField]
private float moveSpeed = 100;
[SerializeField]
private float turnSpeed = 5f;
private void Awake()
{
characterController = GetComponent<CharacterController>();
animator = GetComponentInChildren<Animator>();
}
private void Update()
{
var horizontal = Input.GetAxis("Horizontal");
var vertical = Input.GetAxis("Vertical");
var movement = new Vector3(horizontal, 0, vertical);
characterController.SimpleMove(movement * Time.deltaTime * moveSpeed);
animator.SetFloat("Speed", movement.magnitude);
if (movement.magnitude > 0)
{
Quaternion newDirection = Quaternion.LookRotation(movement);
transform.rotation = Quaternion.Slerp(transform.rotation, newDirection, Time.deltaTime * turnSpeed);
}
}
}
@Ziedch
Copy link
Copy Markdown

Ziedch commented Jun 28, 2021

very instructive script but if anyone doesn't know C# hewon't understand anything and can't adapt the script to his game or whatever he's doing.

@WilliamLuppi
Copy link
Copy Markdown

Nice

@OpenEvade
Copy link
Copy Markdown

very instructive script but if anyone doesn't know C# hewon't understand anything and can't adapt the script to his game or whatever he's doing.

no they will, just use bolt or visual scripting

@rustamovunus950-cpu
Copy link
Copy Markdown

ZombieRun2D

@rustamovunus950-cpu
Copy link
Copy Markdown

ZombieRun2D

@bogkirla-ops
Copy link
Copy Markdown

using UnityEngine;

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

void Update()
{
    float x = Input.GetAxis("Horizontal");
    float z = Input.GetAxis("Vertical");

    Vector3 move = new Vector3(x, 0, z);
    transform.Translate(move * speed * Time.deltaTime);
}

}using UnityEngine;

public class MoneySystem : MonoBehaviour
{
public int money = 1000;

public void AddMoney(int amount)
{
    money += amount;
    Debug.Log("Баланс: $" + money);
}

public void RemoveMoney(int amount)
{
    money -= amount;
    Debug.Log("Баланс: $" + money);
}

}using UnityEngine;

public class Job : MonoBehaviour
{
public MoneySystem moneySystem;

void OnTriggerEnter(Collider other)
{
    if(other.CompareTag("Player"))
    {
        moneySystem.AddMoney(500);
        Debug.Log("Ты получил зарплату!");
    }
}

}using UnityEngine;

public class CarController : MonoBehaviour
{
public float speed = 10f;
public float turnSpeed = 50f;

void Update()
{
    float move = Input.GetAxis("Vertical") * speed * Time.deltaTime;
    float turn = Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime;

    transform.Translate(0, 0, move);
    transform.Rotate(0, turn, 0);
}

}

@nishatmondol1111-cmyk
Copy link
Copy Markdown

using UnityEngine;

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

void Update()
{
    // কীবোর্ডের ইনপুট নেওয়া (W, A, S, D)
    float moveHorizontal = Input.GetAxis("Horizontal");
    float moveVertical = Input.GetAxis("Vertical");

    // মুভমেন্ট ভেক্টর তৈরি করা
    Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

    // ক্যারেক্টারকে মুভ করানো
    transform.Translate(movement * speed * Time.deltaTime);
}

}

@nishatmondol1111-cmyk
Copy link
Copy Markdown

50

@nishatmondol1111-cmyk
Copy link
Copy Markdown

@nishatmondol1111-cmyk
Copy link
Copy Markdown

50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment