Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Albano.conte · May 24, 2012 at 04:47 PM · shooter

I need help scripting a shooter

I'm quite new to programming, my teacher asked us to make a shooter with a few limitations, like the enemies can only attack every 5 seconds and such. I'm nearly done, however unity tells me I've made at least 11 mistakes, here's the code of the MainCharacter and Enemy scripts:

using UnityEngine; using System.Collections;

public class Enemy : MonoBehaviour { void Start () {

 }
 public float Velocidad = 10;
 private bool Atacar = false;
 RaycastHit RCH;
 public float DistanciaParaAtacar = 20;
 
 void Update () 
 {
     transform.LookAt(MainCharacter.Jugador.position);
     transform.position += transform.forward * Time.deltaTime * Velocidad;
     if (Vector3.Distance(this.transform.position, MainCharacter.Jugador.position) < DistanciaParaAtacar)
     {
     //Atacar
     }
     transform.LookAt(MainCharacter.Jugador.position);
     if (Physics.Raycast(transform.position,transform.forward, out RCH, Mathf.Infinity))
     {
             if (RCH.collider.gameObject.layer == MainCharacter.LAYER_MAIN_CHARACTER)
         {
             MainCharacter mc = (MainCharacter)RCH.collider.GameObject.GetComponent(typeof(MainCharacter));
             mc.TakeDamage(20);
         }
     }
 }
 public float Vida = 200;
 public void TakeDamage(float damage)
 {
     Vida -= damage;
     if (Vida <= 0)
     {
         GameObject.Destroy(this.gameObject);
     }
 }

}

using UnityEngine; using System.Collections;

public class MainCharacter : MonoBehaviour { public GameObject Jugador; void Start () {

 }
 RaycastHit RCH;
 void Update () 
 {
     if (Input.GetMouseButtonDown(0))
     {
         if (Physics.Raycast(Camera.mainCamera.transform.position, Camera.mainCamera.transform.forward, out RCH, Mathf.Infinity))
         {
             if (RCH.collider.GameObject.layer == LAYER_ENEMY)
             {
                 Enemy e = (Enemy)RCH.collider.GameObject.GetComponent(typeof(Enemy));
                 if (e)
                 { 
                 e.TakeDamage(50);
                 }
             }
         }
     }
 }
 public float Vida = 200;
 public void TakeDamage(float damage)
 {
     Vida -= damage;
     if (Vida <= 0)
     {
     Application.LoadLevel(0);
     }
 }

}

What it should do is allow both my player and my enemies to attack, and when they hit each other using a raycast, they should substract from the var Vida, also when Vida is 0 in enemies, they should be destroyed, and in the player, the whole proyect should reload. However the error log basically says that theres problems with the MainCharacter.Jugador.Transform

If someone could help me I'd be very grateful. Please answer as fast as you can.

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · May 24, 2012 at 05:11 PM 1
Share

Can you post the unity error log please?

avatar image Kevin_C · May 24, 2012 at 05:15 PM 1
Share

what does it do? what should it do?

and please format the rest of your code.

avatar image Lo0NuhtiK · May 24, 2012 at 05:43 PM 1
Share

Anyone else notice how the school assignment questions always seem like the $$anonymous$$cher's aren't $$anonymous$$ching anything, rather just saying "Hey, make it do this kinda stuff." and then going back to the coffee room... ? You'd think since these things are school assignments the $$anonymous$$cher's would have taught (or be $$anonymous$$ching) how these things are done, ins$$anonymous$$d of throwing a computer at the student and sending them to this answer board.

avatar image whydoidoit · May 24, 2012 at 05:46 PM 1
Share

I'm beginning to feel like I'm back in high school looking at all of these projects ;)

Now that was a long time ago... Not sure Unity would run on a Radio Shack TRS80 III

avatar image torrente · May 24, 2012 at 08:01 PM 0
Share

Just looking over the code, I see a bunch of undefined variables, including the one you pointed out in your question. It looks like you are also trying to use an entire class as an instance as well. Check that and post up the rest of the errors.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Vertical Shooter Joystick Setup 0 Answers

projectile to cursor for a side scrolling shooter 0 Answers

My Enemy AI doesn't work(FPS). 1 Answer

Unity FPS Tutorial delted?! 3 Answers

Error in code I cannot fix 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges