using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { public float movespeed; public GameObject[] targets; // Start is called before the first frame update void Start() {
} // Update is called once per frame void Update() { float Horizontalinput = Input.GetAxis("Horizontal"); transform.Translate(Vector3.forward*Horizontalinput*movespeed*Time.deltaTime); if (Input.GetKey(KeyCode.Space)) { if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.left), out RaycastHit hit, 5f)) { Debug.Log("Hit Something"); // Debug.Log(hit.distance); // Check if the hit object has a Rigidbody Rigidbody hitRigidbody = hit.rigidbody; if (hitRigidbody != null) { // Apply upward force if Rigidbody exists hitRigidbody.velocity = Vector3.up; } else { Debug.Log("No Rigitbody"); } // Check if the hit object is in the targets array //for (int i = 0; i < targets.Length; i++) //{ // if (hit.collider.gameObject == targets[i]) // { // Destroy(targets[i]); // Destroy the specific target // break; // } //} } else { Debug.Log("Not Hitting"); } } } }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float movespeed;
public GameObject[] targets;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float Horizontalinput = Input.GetAxis("Horizontal");
transform.Translate(Vector3.forward*Horizontalinput*movespeed*Time.deltaTime);
if (Input.GetKey(KeyCode.Space))
{
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.left), out RaycastHit hit, 5f))
{
Debug.Log("Hit Something");
// Debug.Log(hit.distance);
// Check if the hit object has a Rigidbody
Rigidbody hitRigidbody = hit.rigidbody;
if (hitRigidbody != null)
{
// Apply upward force if Rigidbody exists
hitRigidbody.velocity = Vector3.up;
}
else
{
Debug.Log("No Rigitbody");
}
// Check if the hit object is in the targets array
//for (int i = 0; i < targets.Length; i++)
//{
// if (hit.collider.gameObject == targets[i])
// {
// Destroy(targets[i]); // Destroy the specific target
// break;
// }
//}
}
else
{
Debug.Log("Not Hitting");
}
}
}
}
💪🔥
❤