Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shoot : MonoBehaviour
{
private Camera camera;
void Update()
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward), Color.red);
if (Input.GetMouseButton(0))
{
Ray ray = new Ray(transform.position, Vector3.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
StartCoroutine(CreateSphere(hit.point));
print(hit.collider.name);
}
}
}
IEnumerator CreateSphere(Vector3 pos)
{
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.position = pos;
yield return new WaitForSeconds(1);
Destroy(sphere);
}
}
using System.Collections.Generic;
using UnityEngine;
public class Shoot : MonoBehaviour
{
private Camera camera;
void Update()
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward), Color.red);
if (Input.GetMouseButton(0))
{
Ray ray = new Ray(transform.position, Vector3.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
StartCoroutine(CreateSphere(hit.point));
print(hit.collider.name);
}
}
}
IEnumerator CreateSphere(Vector3 pos)
{
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.position = pos;
yield return new WaitForSeconds(1);
Destroy(sphere);
}
}