Question by
RageevanGames · Nov 28, 2016 at 03:24 PM ·
programmingprojectiledamageprojectilesprogramming-basics
How to make my snowball model to actually shoot like a projectile?
Well i dont know how to script, but i just need it as fastest as possible, a script that can make a model actually shoot, i already have my shootings script. That kinda does damage by online clicking left mouse button.
using UnityEngine; using System.Collections;
public class MeleeSystem : MonoBehaviour {
public int minDamage = 40;
public int maxDamage = 49;
public float weaponRange = 20f;
public Camera MainCamera;
private TreeHealth treeHealth;
private BasicAI basicAi;
private void Update()
{
Ray ray = MainCamera.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));
RaycastHit hitInfo;
Debug.DrawRay(ray.origin, ray.direction * weaponRange, Color.green);
if (Input.GetKeyDown(KeyCode.Mouse0))
{
if (Physics.Raycast(ray, out hitInfo, weaponRange))
{
if (hitInfo.collider.tag == "playerHealth") // If we hit the tag "Tree"
{
treeHealth = hitInfo.collider.GetComponentInParent<TreeHealth>();
AttackTree();
}
else if (hitInfo.collider.tag == "Enemy") // If we hit the tag "Enemy"
{
basicAi = hitInfo.collider.GetComponent<BasicAI>(); // Find the BasicAi script from the enemy
AttackEnemy();
}
}
}
}
private void AttackTree()
{
Debug.Log("Hit Enemy");
int damage = Random.Range(minDamage, maxDamage);
treeHealth.health -= damage;
}
private void AttackEnemy()
{
int damage = Random.Range(minDamage, maxDamage);
basicAi.TakeDamage(damage);
}
}
Comment
Your answer
Follow this Question
Related Questions
2 Issues with my SHUMP game 0 Answers
Unity bug with scripts 0 Answers
Projectile with direction 0 Answers
How to deal damage to only enemy hit? 2 Answers
2D Weapon Rotation Behaviour Changes on Flipping Sprite? 1 Answer