Hi,
I started working with Unity just a few days ago. I never learn any programming language and I’m currently to make examples from youtube. I would like to create a shooting bow or be able to throw objects.
Unfortunately, one of the tutorials is a script in JavaScript, and in Unity I can not create it.
Can someone help me write the same, but in C #
Below I am sending the script and the final result.
In this project I have another scripts to:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BowScript : MonoBehaviour
{
float _charge;
public float chargeMax;
public float chargeRate;
public KeyCode fireButton;
public Transform spawn;
public Rigidbody arrowObj;
void Update()
{
if(Input.GetKey(fireButton) && _charge < chargeMax)
{
_charge += Time.deltaTime * chargeRate;
Debug.Log(_charge.ToString());
}
if(Input.GetKayUp(fireButton))
{
Rigidbody arrow = Instantiate(arrowObj, spawn.position, Quaternion.identity) as Rigidbody;
arrow.AdForce(spawn.forward * _charge, ForceMode.Impulse);
_charge = 0;
}
}
and the second one
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArrowScript : MonoBehaviour
{
public int damage;
void OnTriggerEnter(Collider col)
{
if (col.GetComponet<EnemyStats>())
{
EnemyStats stats = col.GetComponent<EnemyStats>();
stats.Hit(damage);
}
}
}
Thank you in advance for all your help.