Hi I have been trying to swap some code from js to c# but am still very new to this I cant work out where I have gone wrong on the Vector3 line any help would be amazing, I have made the problem line pink.
using UnityEngine;
using System.Collections;
public class HandGunDamage : MonoBehaviour
{
int DamageAmount = 5;
float TargetDistance;
float AllowedRange = 15f;
void Update()
{
if (Input.GetButtonDown(“Fire1”))
{
RaycastHit Shot;
if (Physics.Raycast(transform.position, transform.TransformDirection Vector3,forward, Shot))
{
TargetDistance = Shot.distance;
if (TargetDistance < AllowedRange)
{
Shot.transform.SendMessage(“DeductPoints”, DamageAmount);
}
}
}
}
}
Please read this page for how to post code nicely on the forums: Using code tags properly
Your code:
public class HandGunDamage : MonoBehaviour
{
int DamageAmount = 5;
float TargetDistance;
float AllowedRange = 15f;
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
RaycastHit Shot;
if (Physics.Raycast(transform.position, transform.TransformDirection Vector3,forward, Shot))
{
TargetDistance = Shot.distance;
if (TargetDistance < AllowedRange)
{
Shot.transform.SendMessage("DeductPoints", DamageAmount);
}
}
}
}
}
I believe you want the line to read:
transform.TransformDirection(Vector3.forward) /* well that section of it */
Sorry, I believe you have another issue, so this would be the full line:
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out Shot))
Just added ‘out’ for ‘out Shot’ to match the method’s signature.
You can include the range in the raycast itself, if you prefer.
Also, I would recommend against using SendMessage. Instead, try to call a method on the script directly.
Shot.GetComponent<YourScript>().DeductPoints(DamageAmount);
// or, if you're unsure if the target is correct...This is an option:
YourScript ys = Shot.GetComponent<YourScript>();
if(ys != null) ys.DeductPoints(DamageAmount);
Is there a free program to easily format and indent random code?
IDEs and I’ve seen a few tools online. Guess it depends on the format you want. Just search for it 
I have been searching, but I’m not sure I had teh right keywords or no where to look at! For c# at leasyt
I had used mono and notepad ++, hasn’t seen any, I tried visual m$ stuff but it keep asking for login and then log me out so screw that lol
Maybe you should make a thread if you have some sort of question completely unrelated to this topic.
Are you saying your IDE doesn’t format/indent code? I’m confused.
Many Thanks I just swapped the line out for yours and it’s running now, can I please ask why the out is needed for shot just so I know when to use sorry for being a pain just getting used to coding
Cool, glad it’s working for you.
As for why ‘out’ is needed; it’s part of the method signature. If you’re asking what “out” is/does, it’s a variable that’s set inside the function. It also passes a reference to the storage location of the variable. You do not need to initialize a variable you send with the ‘out’ parameter, because it must be set by the method before returning.
Here’s a quick example with an integer:
void Blah(out int a) {
a = 5;
}
void Blah2(int a) {
a = 5;
}
void SomeMethod() {
int b = 100;
Blah(out b); // 'b' will be '5' upon returning.
Blah2(b); // 'b' is 100
}
Hope that helps a bit 
1 Like
Thank’s you have been an amazing help and sorry to be a pain but im having another problem with a line on a different script please could you take a look at this sorry for being a pain
void DeductPoints(int DamageAmount)
in the full script so not out of context :
using UnityEngine;
using System.Collections;
public class EnemyScript : MonoBehaviour
{
int EnemyHealth = 10;
}
void DeductPoints (int DamageAmount)
{
EnemyHealth -= DamageAmount;
}
void Update(){
if (EnemyHealth <= 0){
Destroy(gameObject);
}
}
}}
I don’t mind helping. Generally it’s a good idea to make a new thread about an issue, but since we’re here… 
Also, it helps if you say what the problem is 
If the script is written exactly like that, you have a brace out of place. There should be no closing brace on line #8. Was that it or something else?
By the way, I’d advise that you simply move your health and Destroy inside the DeductPoints method, and get rid of the Update() method entirely (since it would no longer be being used).
1 Like
Thanks and sorry been a long night
the problem line is line 10 it keeps coming up in the console saying error unexpected symbol ‘void’ i just cant work it out and thanks i will try taking out the update section like you said
Sure, so that’s related to the first part of what I said, about the closing brace above it which shouldn’t be there. Just delete it
I think you may need to delete one closing brace at the end of the script, too.
1 Like
Thanks so much you have been amazing i have been up all night trying to work out where i went wrong 
Glad it’s all sorted out
Take care =)