docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Vector multiplication

    To multiply vectors, use the *:

    // Unity Mathematics example
    void ComponentwiseVectorMultiplyUnityMathematics()
    {
       var v0 = new float4(2.0f, 4.0f, 6.0f, 8.0f);
       var v1 = new float4(1.0f, -1.0f, 1.0f, -1.0f);
       var result = v0 * v1;
       // result == new float4(2.0f, -4.0f, 6.0f, -8.0f).
    }
    

    This is a common way of writing SIMD code, which applies a single instruction to multiple data elements. Other operators such as addition, subtraction, and division work in the same way.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)