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 PEF · Mar 05, 2012 at 09:49 PM · windzone

How to link a Main Camera via script and scripting for WindZone

I wanted to ask how can I link a main camera to a script to prevent an error occurring saying could not find a wind zone to link to Main Camera (WindzoneController) UnityEngine.Debug:LogError(Object)?

I am currently working on an environment which consists of grass and trees affected by wind however I am looking to code code the wind zone so far I have two scripts which are both attached to the wind zone object in my environment and the main camera but I get these following errors. I have posted my code underneath the errors if anyone can help me with this it will be most appreciated.

  1. could not find a wind zone to link to Main Camera (WindzoneController) UnityEngine.Debug:LogError(Object)

    1. NullReferenceException: Object reference not set to an instance of an object ScriptableWindzoneInterface.GetWindZoneValue (System.String MemberName) (at Assets/Standard Assets (Mobile)/ScriptsScriptableWindzoneInterface.cs:150)

    2. IndexOutOfRangeException: Array index is out of range. (wrapper stelemref) object:stelemref (object,intptr,object) ScriptableWindzoneInterface.set_WindTurbulence (Single value) (at Assets/Standard Assets (Mobile)/Scripts/ScriptableWindzoneInterface.cs:67) WindzoneController.Update () (at Assets/Standard Assets (Mobile)/Scripts/WindzoneController.cs:27)

ScriptableWindzoneInterface

using UnityEngine;

 using System.Collections;

 using System.Reflection ;

  

 // Provides a scriptable interface to a windzone

 /* 

  

  */

 public class ScriptableWindzoneInterface : MonoBehaviour { 

     // Private vars ===================================

    

     // The windzone component

     private Component m_WindzoneComponent ;

    

     // The system qualified type of the windzone

     private System.Type m_WindzoneType ;

    

     // Used to pass an argument to WindZone setter functions

     object[] m_WindZoneArgs = new object[1] ;

    

     // Public properties ==============================

    

     // `radius`

     public float Radius {

         get

         {

             // Return the value of `radius`

             return (float)GetWindZoneValue( "get_radius" ) ;

         }

         set

         {

             // Set the argument

             m_WindZoneArgs[1] = value ;

            

             // Set the value of `windMain`

             SetWindZoneValue( "set_radius" , m_WindZoneArgs ) ;

         }

     }

    

     // `windMain`

     public float WindMain {

         get

         {

             // Return the value of `windMain`

             return (float)GetWindZoneValue( "get_windMain" ) ;

         }

         set

         {

             // Set the argument

             m_WindZoneArgs[1] = value ;

            

             // Set the value of `windMain`

             SetWindZoneValue( "set_windMain" , m_WindZoneArgs ) ;

         }

     }

    

     // `windTurbulence`

     public float WindTurbulence {

         get

         {

             // Return the value of `windTurbulence`

             return (float)GetWindZoneValue( "get_windTurbulence" ) ;

         }

         set

         {

             // Set the argument

             m_WindZoneArgs[1] = value ;

            

             // Set the value of `windTurbulence`

             SetWindZoneValue( "set_windTurbulence" , m_WindZoneArgs ) ;

         }

     }

    

     // `windPulseMagnitude`

     public float WindPulseMagnitude {

         get

         {

             // Return the value of `windPulseMagnitude`

             return (float)GetWindZoneValue( "get_windPulseMagnitude" ) ;

         }

         set

         {

             // Set the argument

             m_WindZoneArgs[1] = value ;

            

             // Set the value of `windPulseMagnitude`

             SetWindZoneValue( "set_windPulseMagnitude" , m_WindZoneArgs ) ;

         }

     }

    

     // `windPulseFrequency`

     public float WindPulseFrequency {

         get

         {

             // Return the value of `windPulseFrequency`

             return (float)GetWindZoneValue( "get_windPulseFrequency" ) ;

         }

         set

         {

             // Set the argument

             m_WindZoneArgs[1] = value ;

            

             // Set the value of `windPulseMagnitude`

             SetWindZoneValue( "set_windPulseFrequency" , m_WindZoneArgs ) ;

         }

     }

    

     // Public functions ===============================

    

     // Find and link against the windzone

     public void Init () {

     

        

         // Get the windzone of this game object

         m_WindzoneComponent = GetComponent("WindZone");

        

         // Ensure there was a windzone to link to

         if ( m_WindzoneComponent == null ) {

             // Log the error

             Debug.LogError( "Could not find a wind zone to link to: " + this ) ;

            

             // Disable this script for the remainder of the run

             this.enabled = false;

            

             // Stop here

             return ;

         }

        

         // Get the system qualified type

         m_WindzoneType = m_WindzoneComponent.GetType() ;

        

     }

    

     // Private functions =============================

    

     // Set a WindZone property value

     void SetWindZoneValue ( string MemberName , object[] args ){

         // Call the setter

         m_WindzoneType.InvokeMember(

                                     MemberName ,

                                     BindingFlags.InvokeMethod | BindingFlags.Instance ,

                                     null ,

                                     m_WindzoneComponent ,

                                     args ) ;

     }

    

     // Get a WindZone property value

     object GetWindZoneValue ( string MemberName ){

         // Call the getter

         return m_WindzoneType.InvokeMember(

                                            MemberName ,

                                            BindingFlags.InvokeMethod | BindingFlags.Instance ,

                                            null ,

                                            m_WindzoneComponent ,

                                            null ) ;

     }

 }

WindzoneController

 using UnityEngine;

 using System.Collections;

  

 // Allows Control Over WindZone Component

  

 // Note: The WindZone & This Script Must Be Attached To The Same Game Object

  

 public class WindzoneController : ScriptableWindzoneInterface {

  

     // Use this for initialization

     void Start () {

         // Tell the ScriptableWindzoneInterface to initialize

         base.Init() ;

        

         // Example: Log the current settings

         Debug.Log( "The Starting Settings Of The Windzone Are: Main=" + WindMain

                   + ", Turbulence=" + WindTurbulence

                   + ", Pulse Magnitude=" + WindPulseMagnitude

                   + ", Pulse Frequency=" + WindPulseFrequency ) ;

     }

    

     // Update is called once per frame

     void Update () {

        

         // Example: Setting each of the values

         WindMain = Mathf.PingPong( ( Time.time / 2.0F ) , 1.0F ) ;

         WindTurbulence = WindMain ;

         WindPulseMagnitude = WindMain ;

         WindPulseFrequency = WindMain ;

         Radius = WindMain;

     }

 }

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

how to change wind main property and transform of wind zone through c# script? 1 Answer

How can I change WindZone settings with a script? 4 Answers

Accessing 'Wind Main' on windzone objects thru script 0 Answers

Referencing non static variables from another script? C# 2 Answers

I need help instantiateing a bullet 0 Answers


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