UNİTY 3D FUNCTIONS - RAYCAST HİT
RAYCAST HİT:
public class Flashlight : MonoBehaviour
{
//Player
Movement
public float speed;
private bool aciksa;
public GameObject flashlight;
RaycastHit hit;
private void Start()
{
aciksa = true;
}
{
Vector3 playerInput = new Vector3(Input.GetAxis("Horizontal"), 0f,
Input.GetAxis("Vertical"));
Vector3 moveVelocity = playerInput *
Time.deltaTime * speed;
// moveVelocity
= Hareket Etme Hızı
transform.Translate(moveVelocity);
//Flaslight
if (Input.GetKeyDown(KeyCode.F))
{
if (aciksa)
{
flashlight.GetComponent<Light>().enabled = false;
aciksa = false;
}
else
{
flashlight.GetComponent<Light>().enabled = true;
aciksa = true;
}
}
//Fire
// GameObject.FindGameObjectWithTag("Main Camera"); == Camera.main
if
(Input.GetMouseButtonDown(0))
{
if
(Physics.Raycast(Camera.main.transform.position, transform.forward, out hit , Mathf.Infinity))
{
if
(hit.collider.gameObject.tag == "Enemy")
{
Destroy(hit.collider.gameObject);
}
}
}
}
}
Sarı ile çizdiklerim bu ders içinde yazılmış kodlardır. Bu
kodlar sayesinden Mouse’nin sol tuşu ile oyun içerisinden bir şeye bastığımızda
objeyi yok eder.
Diğer kodlar önceki derslerin kodları.
Hiç yorum yok: