Jimmy vegas fps tutorial converting to c#
Hi I was wondering if anyone can convert Jimmy vegas's javascript to c# for me, I have got up to episode 4 with converting to c# but I am stuck on episode 5. Here's episode 4 https://www.youtube.com/watch?v=N7YNWewemVo using System.Collections; using System.Collections.Generic; using UnityEngine;
public class HandGunDamage : MonoBehaviour {
public int damageAmount = 5;
public float targetDistance;
public float allowedRange = 15;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire1"))
{
RaycastHit shot;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out shot))
{
targetDistance = shot.distance;
if (targetDistance < allowedRange)
{
shot.transform.SendMessage("DeductPoints", damageAmount);
}
}
}
}
}
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class EnemyScript : MonoBehaviour {
private int enemyHealth = 10;
// Use this for initialization
private void DeductPoints (int DamageAmount)
{
enemyHealth -= DamageAmount;
}
void Start () {
}
// Update is called once per frame
void Update () {
if (enemyHealth <= 0)
{
Destroy(gameObject);
}
}
}
(Skipping the near the end will show the code in full) However Im stuck on episode 5 https://www.youtube.com/watch?v=MWBgSxk0y9k&t=761s using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ScriptAnimate : MonoBehaviour {
GameObject UpCurs;
GameObject DownCurs;
GameObject RightCurs;
GameObject LeftCurs;
public void WaitingAnim()
{
yield return new WaitForSeconds(2);
UpCurs.GetComponent<Animator>().enabled = false;
DownCurs.GetComponent<Animator>().enabled = false;
RightCurs.GetComponent<Animator>().enabled = false;
LeftCurs.GetComponent<Animator>().enabled = false;
}
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
upCurs.GetComponent("Animator").enabled = true;
downCurs.GetComponent("Animator").enabled = true;
rightCurs.GetComponent("Animator").enabled = true;
leftCurs.GetComponent("Animator").enabled = true;
WaitingAnim();
}
}
} this is what I got so far and Im getting alot of problems, such as WaitingAnim() cannot be an iterator block. Thanks if anyone helps, if you are proficient in c# and javascript im sure this will be easy enough :) I will post the c# version to the tutorial so everyone can see (people have done that on previous versions)
Episode 4 javascript: //Gunfire script for FPS Tutorial 004 by Jimmy Vegas
function Update () { if(Input.GetButtonDown("Fire1")) { var gunsound : AudioSource = GetComponent.(); gunsound.Play(); GetComponent.().Play("GunShot"); } } episode 5 javascript: //Jimmy Vegas Unity Tutorial //These scripts will allow you to inflict damage with your gun
//THIS FIRST SCRIPT SHOULD BE PLACED ON YOUR GUN MECHANICS OBJECT
var DamageAmount : int = 5; var TargetDistance : float; var AllowedRange : float = 15;
function Update () { if(Input.GetButtonDown("Fire1")) {
var Shot : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), Shot)) {
TargetDistance = Shot.distance;
if (TargetDistance < AllowedRange) {
Shot.transform.SendMessage("DeductPoints", DamageAmount);
}
}
}
}
//==================================
//THIS SCRIPT SHOULD BE PLACED ON YOUR ENEMY
var EnemyHealth : int = 10;
function DeductPoints (DamageAmount : int) { EnemyHealth -= DamageAmount; }
function Update () { if (EnemyHealth <= 0) { Destroy(gameObject); } }
Answer by zachwuzhere · Feb 27, 2017 at 05:45 AM
This is a good site for converting Javascript (aka Unityscript) to C#. http://www.m2h.nl/files/js_to_c.php
Your answer
Follow this Question
Related Questions
Help in conversion of variable types c# 1 Answer
Health Script 2 Answers
Convert Java to C# 2 Answers
How to load level after typing somthing? 1 Answer
Jump Issue :( 1 Answer