RayCast von Maincamera aus, damit die Kugel die man Abfeuert auch im Crosshair landet

This commit is contained in:
klikev 2024-06-16 13:25:46 +02:00
parent 588a0f1212
commit 79c7d841af
8 changed files with 1132 additions and 205 deletions

View File

@ -32,7 +32,6 @@ Transform:
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: m_Children:
- {fileID: 6605893028012961459} - {fileID: 6605893028012961459}
- {fileID: 2485312180149050413}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!54 &7689678004430099734 --- !u!54 &7689678004430099734
@ -74,40 +73,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: cf678ed456c71c949b0b1a2b01e9f32b, type: 3} m_Script: {fileID: 11500000, guid: cf678ed456c71c949b0b1a2b01e9f32b, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
child: {fileID: 1549001692297207422}
dataBullet: {fileID: 11400000, guid: cafd241bae342f446ae8141cc5d72daf, type: 2} dataBullet: {fileID: 11400000, guid: cafd241bae342f446ae8141cc5d72daf, type: 2}
rb: {fileID: 7689678004430099734} lifetime: 3
--- !u!1 &1549001692297207422
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2485312180149050413}
m_Layer: 0
m_Name: PivotPoint
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2485312180149050413
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1549001692297207422}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.1, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 3286218375903244322}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &4152829191026619603 --- !u!1 &4152829191026619603
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -132,7 +132,7 @@ BoxCollider:
m_LayerOverridePriority: 0 m_LayerOverridePriority: 0
m_IsTrigger: 0 m_IsTrigger: 0
m_ProvidesContacts: 0 m_ProvidesContacts: 0
m_Enabled: 1 m_Enabled: 0
serializedVersion: 3 serializedVersion: 3
m_Size: {x: 1, y: 1, z: 1} m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0} m_Center: {x: 0, y: 0, z: 0}
@ -161,9 +161,9 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8363807481264483936} m_GameObject: {fileID: 8363807481264483936}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: -0, y: 0.26252207, z: -0, w: 0.96492606} m_LocalRotation: {x: 0, y: 0.26252607, z: 0, w: 0.96492493}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 0.9699999, y: 0.3, z: 0.31}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: m_Children:
- {fileID: 1313371464610265781} - {fileID: 1313371464610265781}

View File

@ -1059,7 +1059,7 @@ MonoBehaviour:
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0 m_IntArgument: 0
m_FloatArgument: 0 m_FloatArgument: 0
m_StringArgument: JanScene m_StringArgument: KevinSceneGun
m_BoolArgument: 0 m_BoolArgument: 0
m_CallState: 2 m_CallState: 2
--- !u!114 &2019160122 --- !u!114 &2019160122

File diff suppressed because it is too large Load Diff

View File

@ -4,31 +4,39 @@ using UnityEngine;
public class BulletMoving : MonoBehaviour public class BulletMoving : MonoBehaviour
{ {
public GameObject child;
public DataBullet dataBullet; public DataBullet dataBullet;
public float lifetime = 3f; public float lifetime = 3f;
[SerializeField]
private Rigidbody rb; private Rigidbody rb;
private Vector3 direction = new Vector3(0f,0f,0f); private Vector3 direction;
private float time = 0f; private float time = 0f;
private Ray ray;
private RaycastHit hit;
private void die(float lifetime){ private void die(float lifetime){
if(time > lifetime){ if(time > lifetime){
GameObject.Destroy(this.gameObject); GameObject.Destroy(this.gameObject);
} }
} }
private void CheckForColliders(){
if(Physics.Raycast(ray, out hit)){ //wenn true wird durch out in variable hit ein RayCastHit gespeichert
direction = hit.point - transform.position;//Richtung in die, die Kugel fliegt
}
}
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
rb = this.GetComponent<Rigidbody>(); rb = this.GetComponent<Rigidbody>();
direction = child.transform.position - transform.position;
ray = Camera.main.ViewportPointToRay(new Vector3(0.5f,0.5f,0f));
CheckForColliders();
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {

View File

@ -13,5 +13,5 @@ MonoBehaviour:
m_Name: DataBullet m_Name: DataBullet
m_EditorClassIdentifier: m_EditorClassIdentifier:
damage: 10 damage: 10
speed: 20 speed: 5
ammo: 4 ammo: 4

View File

@ -8,7 +8,6 @@ public class WeaponScript : MonoBehaviour
public GameObject spawnpoint; public GameObject spawnpoint;
public GameObject bullet; public GameObject bullet;
private void shoot(){ private void shoot(){
if(Input.GetKeyDown(KeyCode.Mouse0)){ if(Input.GetKeyDown(KeyCode.Mouse0)){
Instantiate(bullet,spawnpoint.transform.position,transform.rotation); Instantiate(bullet,spawnpoint.transform.position,transform.rotation);

View File

@ -3,7 +3,8 @@
--- !u!78 &1 --- !u!78 &1
TagManager: TagManager:
serializedVersion: 2 serializedVersion: 2
tags: [] tags:
- PlayerView
layers: layers:
- Default - Default
- TransparentFX - TransparentFX