Answer the question
In order to leave comments, you need to log in
Archery, how to implement the release of the arrow?
There is a code:
using UnityEngine;
using System.Collections;
public class Bow : MonoBehaviour {
public Transform arrowPrefab; //префаб стрелы
private bool checkArrow; //проверка создания стрелы(создана или нет)
private Transform arrow; //созданная стрела в окне
public float speedArrow; // скорость стрелы
private Transform transformSpawners;//расположение лука
// Use this for initialization
void Start () {
checkArrow = false;
transformSpawners = gameObject.transform;
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0) && checkArrow == false) {
arrow = (Transform)Instantiate(arrowPrefab,
transformSpawners.position,
Quaternion.identity);
arrow.transform.rotation = transformSpawners.rotation;
checkArrow = true;
}
if (checkArrow && Input.GetMouseButton(0)) {
arrow.transform.position = GameObject.Find ("Spawn").transform.position;
}
if(checkArrow && Input.GetMouseButtonUp(1))
{
Destroy(arrow.gameObject);
checkArrow = false;
}
if(checkArrow && Input.GetMouseButtonUp(0))
{
checkArrow = false;
}
}
}
if(checkArrow && Input.GetMouseButtonUp(0))
{
checkArrow = false;
}
Answer the question
In order to leave comments, you need to log in
arrowPrefab do you have an object with a Rigidbody ?
AddForce works great if there is a physical body. Just do not forget that the type of force is different, for the case of an arrow, momentum is great.
something like this
arrow.AddForce(arrow.transform.forward * forcePower, ForceMode.Impulse);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question