Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Gonza0012 · Sep 20, 2011 at 01:06 AM · javascripterror

What's wrong with this (Java)Script? Some parts don't work

Hi

I was programmin a simple script, when I test it I note that some parts din't work. Here's the Script:


var Velocidad = 0.2;

var Rango = 30;

var RangoMeta = 5;

var RangoAmigo = 10;

var Meta = true;

var Disparar = false;

var Estado = 0;

//--------------------------------------------------------------------------------------------------

//These variables are for the machine gun, this part of the script is no mine

public var PuntoDisparo : Transform; public var Arma : GameObject; public var Aceleracion : float = 1; public var Disparo : GameObject; var FireRate = 0.5; var ClipSize = 30; var ReloadTime = 0.5; private var Reload = false;

function Start(){ var ProrArmas : AutoDestruir = Arma.GetComponent(AutoDestruir); Aceleracion = ProrArmas.Aceleracion; }

//-------------------------------------------------------------------------------------------------

function Update () {

//I look for the transform of a game object tagged "Finish2"

var Objetivo = GameObject.FindWithTag("Finish2");

var PosicionFinish = Objetivo.transform;

//Here I look for the transform of a game object tagged "Player"

var Amigo = GameObject.FindWithTag("Player");

var PosicionAmigo = Amigo.transform;

//And here I look for the transfor of a game object tagged "Enemy

var Enemigo = GameObject.FindWithTag("Enemy");

var PosicionEnemigo = Enemigo.transform;

//--------------------------------

if(Meta == true){ transform.LookAt(PosicionFinish); }

if(Vector3.Distance(PosicionFinish.position, transform.position)

Estado = 1;

}

else{

Estado = 0;

}

if(Vector3.Distance(PosicionEnemigo.position, transform.position)

}

else{

Estado = 0;

}

if(Estado == 0){

Meta = true;

transform.Translate(0, 0, Velocidad);

Disparar = false;

} if(Estado == 1){

transform.Translate(0, 0, 0);

} if(Estado == 2){

transform.Translate(0, 0, 0);

transform.LookAt(PosicionEnemigo);

Meta = false;

Disparar = true;

}

if(Disparar == true)

{

FireRate+=0.5;

}

if(FireRate == 2) { FireRate-= 2; }

if(Disparar == true && FireRate == 1){

//This is for instantiate the game object that is the bullet

var CloneFire : GameObject = Instantiate (Arma, PuntoDisparo.position, gameObject.transform.rotation);

CloneFire.rigidbody.AddRelativeForce(new Vector3(0, 0, Aceleracion), ForceMode.VelocityChange);

//And this is for instantiate a particle system that is the muzzle flash

var CloneDisparo : GameObject = Instantiate (Disparo, PuntoDisparo.position, gameObject.transform.rotation);

}

}


I have three objects in the game: The first one is the enemy, tagged Enemy, and has no scripts. The second one is the "player", tagged Player and has the previous script y finally there is the third one, tagged Finish2.

What I want is that my player moves continuously to Finish2, but, when it find an enemy close it stops, stop looking at Finish2, look at Enemy and shoot to it, it works; what doesn't work is the part that says that my object (Player) must stop when be near the Finish or another game object tagged Player.

There is no errors detected by Unity, and I tried a lot of posibilities to resolve this problem but I could not.

Finally, sorry for my spelling, I'm learning English yet.

Comment
Add comment
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

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

2 People are following this question.

avatar image avatar image

Related Questions

Exception error 1 Answer

Is not a Member of Collisions 2 Answers

Trouble converting player controller from JS to C# 1 Answer

Change gameobject sprite with button 1 Answer

Error Message Coordinates 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