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 /
This question was closed Jan 04, 2015 at 04:55 PM by Graham-Dunnett for the following reason:

Duplicate Question

avatar image
0
Question by BitGlitch · Jan 04, 2015 at 04:55 PM · raycastingraycasthitcs1061

Error with raycast

Hello, In one of my scripts unity is telling me:

Assets/Scripts/Weapons/Laser.cs(76,37): error CS1061: Type UnityEngine.RaycastHit[]' does not contain a definition for transform' and no extension method transform' of type UnityEngine.RaycastHit[]' could be found (are you missing a using directive or an assembly reference?)

and here is my code:

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent (typeof(LineRenderer))]
 
 public class Laser : MonoBehaviour {
     
     public float laserWidth = 1.0f;
     public int damage = 5;
     public float noise = 0f;
     public float maxRange = 10.0f;
     public Color color = Color.green;
     
     
     LineRenderer lineRenderer;
     int length;
     Vector3[] position;
     //Cache any transforms here
     Transform myTransform;
     Transform endEffectTransform;
     //The particle system, in this case sparks which will be created by the Laser
     public ParticleSystem endEffect;
     Vector3 offset;
 
     
     // Use this for initialization
     void Start () {
         lineRenderer = GetComponent<LineRenderer>();
         lineRenderer.SetWidth(laserWidth, laserWidth);
         myTransform = transform;
         offset = new Vector3(0,0,0);
         endEffect = GetComponentInChildren<ParticleSystem>();
         if(endEffect)
             endEffectTransform = endEffect.transform;
     }
     
     // Update is called once per frame
     void Update () {
         RenderLaser();
     }
     
     void RenderLaser(){
         
         //Shoot our laserbeam forwards!
         UpdateLength();
         
         lineRenderer.SetColors(color,color);
         //Move through the Array
         for(int i = 0; i<length; i++){
             //Set the position here to the current location and project it in the forward direction of the object it is attached to
             offset.x =myTransform.position.x+i*myTransform.forward.x+Random.Range(-noise,noise);
             offset.y =myTransform.position.y+i*myTransform.forward.y+Random.Range(-noise,noise);
             offset.z =i*myTransform.forward.z+Random.Range(-noise,noise)+myTransform.position.z;
             position[i] = offset;
             position[0] = myTransform.position;
             
             lineRenderer.SetPosition(i, position[i]);
             
         }
         
         
         
     }
     
     void UpdateLength(){
         //Raycast from the location of the cube forwards
         RaycastHit[] hit;
         hit = Physics.RaycastAll(myTransform.position, myTransform.forward, maxRange);
         int i = 0;
         while(i < hit.Length){
             //Checks if the laser hits a mech's center collider
             if(hit[i].collider.tag == "Mech Center")
             {
                 hit.transform.SendMessageUpwards("ApplyDamageCenter", damage);
             }
 
             //Checks if the laser hits a mech's right arm collider
             if(hit[i].collider.tag == "Mech Right Arm")
             {
                 hit.transform.SendMessageUpwards("ApplyDamageRightArm", damage);
             }
 
             //Checks if the laser hits a mech's left arm collider
             if(hit[i].collider.tag == "Mech Left Arm")
             {
                 hit.transform.SendMessageUpwards("ApplyDamageLeftArm", damage);
             }
 
             
             //Check to make sure we aren't hitting triggers but colliders
             if(!hit[i].collider.isTrigger)
             {
                 length = (int)Mathf.Round(hit[i].distance)+2;
                 position = new Vector3[length];
                 //Move our End Effect particle system to the hit point and start playing it
                 if(endEffect){
                     endEffectTransform.position = hit[i].point;
                     if(!endEffect.isPlaying)
                         endEffect.Play();
                 }
                 lineRenderer.SetVertexCount(length);
                 return;
             }
             i++;
         }
         //If we're not hitting anything, don't play the particle effects
         if(endEffect){
             if(endEffect.isPlaying)
                 endEffect.Stop();
         }
         length = (int)maxRange;
         position = new Vector3[length];
         lineRenderer.SetVertexCount(length);
         
         
     }
 }
 

Does anyone see what is wrong?

Comment
Comments Locked
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

  • Sort: 

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

RaycastHit always returns 0 1 Answer

Can you figure out raycast origin position from RacyastHit? 2 Answers

Vehicle is vibrating on the edge of the ramp/surface when I get the normal of the surface 0 Answers

how detect "OnRaycastOut" 1 Answer

Raycast script help? 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