Looking for feedback from experienced scripters

Okay so this is my first real attempt at writing a script with any type of complexity to it so I apologize in advance if it makes anyone’s eyes bleed. I have attempted to write this purely through what I have learned the last few weeks dealing with script and have minimized my google searching for answers to prevent having a script handed to me. So I ask that any answers not be complete scripts but instead just stear me in the right direction as I am using this as a learning process.

The script below I am attempting to do the following with. I want it to go on a tile on the ground that will (on a timer) change between 4 textures. With each texture I want there to be a different effect given to the player if he is on, or enters, the trigger. the 4 effects are to hurt him, heal him, give him points and give him ammo.

Any input anyone has for this oh so crude attempt at scripting is much appreciated. I am specifically looking for any information pertaining to cleaning the script up and making it more efficient (is there a better way to have written any of it?), any smack in the face errors that stick out, and why unity is giving me an EoF error on the else portions of the trigger functions (are if/else not allowed in trigger functions?). I have taken the time to add a lot of comments to try and give as much information as to what I am trying to do with each part of the script.

var healTexture : Texture2d;
var hurtTexture : Texture2d;
var ammoTexture : Texture2d;
var pointTexture : Texture2d;
var damageAmount = int;
var healAmount = int;
var ammoAmount = int;
var pointAmount = int;
var damageDelay : float = 1;
var healDelay : float = 1;
var interval:float = 10;
var timer:float;

private var nextDamageAllowed : float;
private var nextHealAllowed : float;
private var nextAmmoAllowed : float;
private var nextPointAllowed : float;

function Start(){
timer = Time.time + interval; //the timer is equal to the time in the future
}

function Update(){
if(Time.time >= timer) //if the current time elapsed is equal to or greater than the timer
randomNumer = random.range (1,4);
}
switch(randomNumber){

case 1: HealTexture;//If number is 1, apply HealTexture Function

case 2: HurtTexture;//If number is 2, apply HurtTexture Function

case 3: AmmoTexture;//If number is 1, apply AmmoTexture Function

case 4: PointTexture;//If number is 2, apply PointTexture Function
}

timer = Time.time + interval; //reset the timer

//Apply the healTexture to object
function HealTexture(){
renderer.material.mainTexture = healTexture;
}

//Apply the hurtTexture to object
function HurtTexture(){
renderer.material.mainTexture = hurtTexture;
}
//Apply the ammoTexture to object
function AmmoTexture(){
renderer.material.mainTexture = ammoTexture;
}
//Apply the pointTexture to object
function PointTexture(){
renderer.material.mainTexture = pointsTexture;
}

//When player enters trigger hurt them if the hurtTexture is active
function OnTriggerEnter(thecollision : Collider){
if(theCollision.gameObject.tag == “Player” HurtTexture){
GiveDamage;
}
}
//when player enters trigger heal them if the healTexture is active
else if{
if(theCollision.gameObject.tag == “Player” HealTexture){
GiveHeal;
}
}
//when player enters trigger give them ammo if the AmmoTexture is active
else if{
if(theCollision.gameObject.tag == “Player” AmmoTexture){
GiveAmmo;
}
}
//when player enters trigger give them points if the PointTexture is active
else{
if(theCollision.gameObject.tag == “Player” PointTexture){
GivePoints;
}
//when player stands on trigger hurt them periodically if the HurtTexture is active
function OnTriggerStay(thecollision : Collider){
if(theCollision.gameObject.tag == “Player” HurtTexture){
GivePeriodicDamage;
}
}
//when player stands on trigger heal them periodically if the healTexture is active
else if{
if(theCollision.gameObject.tag == “Player” HealTexture){
GivePeriodicHeal;
}
}
//when player stands on trigger give them ammo periodically if the AmmoTexture is active
else if{
if(theCollision.gameObject.tag == “Player” AmmoTexture){
GivePeriodicAmmo;
}
}
//when player stands on trigger give them points periodically if the PointTexture is active
}else{
if(theCollision.gameObject.tag == “Player” PointTexture){
GivePeriodicPoints;
}
//Function to damage player for OnTriggerEnter
function GiveDamage(){
SendMessage(“ApplyDamage”, damageAmount, SendMessageOptions, DontRequireReceiver);
}
//Function to heal player for OnTriggerenter
function GiveHeal(){
SendMessage(“Heal”, healAmount, SendMessageOptions, DontRequireReceiver);
}
//Function to give ammo to player for OnTriggerEnter
function GiveAmmo(){
gunScript.clips += ammoAmount;
}
//Function to give points to player for OnTriggerEnter
function GivePoints(){
PointManager.points += pointAmount;
}
//Function to hurt player for OnTriggerstay
function GivePeriodicDamage(){
if(Time.time > nextDamageAllowed){
SendMessage(“ApplyDamage”, damageAmount, SendMessageOptions, DontRequireReceiver);
nextDamageAllowed = Time.time + damageDelay;
}
}
//Function to heal player for OnTriggerStay
function GivePeriodicHeal(){
if(Time.time > nextHealAllowed){
SendMessage(“Heal”, healAmount, SendMessageOptions, DontRequireReceiver);
nextHealAllowed = Time.time + healDelay;
}
}
//Function to give ammo to player for OnTriggerStay
function GivePeriodicAmmo(){
if(Time.time > nextAmmoAllowed){
gunScript.clips += ammoAmount;
nextAmmoAllowed = Time.time + ammoDelay;
}
}
//Function to give points to player for OnTriggerStay
function GivePeriodicPoints(){
if(Time.time > nextPointAllowed){
PointManager.points += pointAmount;
nextPointAllowed = Time.time + pointDelay;
}
}

Please use code tags. Also, and I have not read through all the code, when you are declaring your variables, with the integers you are using the = sign, but should be using a : to denote that it IS an int. I am going to read more now…

switch (randomnumber) {
    case blah1:
        code here;
        break;
    case blah2:
        more code here;
        break;
    default:
        even more code here;
        break;
}

You should realy search for the right syntax of commands ( Google ) and it will be alot easier.

1)Random.Range() needs caps.
a) Random.Range() overload with integers is exclusive, does not include the second number. Random.Range(1,4) will return 1,2, 0r 3

  1. Is your switch statement supposed to be inside update? Update() ends after your first if() statement, because you never open the if() with a brace ‘{’.

  2. If the switch is supposed to be in Update, then I assume that the resetting the time is too, which means that you are resetting the timer every frame. If it is not, then you aren’t resetting the timer at all.

  3. In the switch statement you need to make function calls to the other functions. This means that you need to use () to actually call it. The way that you have it is referencing some variable somewhere with the same name as a function - bad news. OR you could put these funcitons in the switch statement and not have external functions, which I wouldn’t do - just giving you the option if you didn’t see it there.

  4. In OnTriggerEnter() use CompareTag() instead of ‘==’, it’s faster.

  5. Again, the () parens are part of the function call. Think of them as part of the name. Without them, you are not calling a function.

  6. Your else if() syntax is off. Google it like appels said.

  7. The logic in your block of if() statements is faulty.

if(theCollision.gameObject.tag == "Player"  HurtTexture) {
     GivePeriodicDamage;
}

This is going to check if there is anything assigned to HurtTexture. So if you have ANY texture in that variable, then you will never make it past this check. You need some way to check if this is the current texture.

  1. SendMessageOptions.DontRequireReceiver a dot, not a comma.